tag:blogger.com,1999:blog-4434108347727659251.post3803331787916542765..comments2022-06-29T08:53:03.580+02:00Comments on Compas Pascal: Delphi is fast, very fastUnknownnoreply@blogger.comBlogger64125tag:blogger.com,1999:blog-4434108347727659251.post-51856425018618242942009-08-26T14:24:50.494+02:002009-08-26T14:24:50.494+02:00One few comments from my side.
IMHO it helps to d...One few comments from my side.<br /><br />IMHO it helps to differentiate between problem, algorithm and implementation. I think you are all using the same algorithm, i.e. walk through the array and count the occurrence of a certain value/compute the mean.<br /><br />The problem: given a set of random numbers in 1 to 100 give me the count of the ones with a certain value (without loss of DJ Brokolihttps://www.blogger.com/profile/02406732601051342935noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-78495621244748507062009-08-14T12:54:03.696+02:002009-08-14T12:54:03.696+02:00My example is multithreading, but the actual threa...My example is multithreading, but the actual thread creation is hidden in the procedure call, which is implemented using TThread.Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-26566778554659682562009-08-14T12:02:23.233+02:002009-08-14T12:02:23.233+02:00Lars, that example you posted isn't multi-thre...Lars, that example you posted isn't multi-threading.<br /><br />Multi-Threading is using multiple threads. Yours only uses 1 thread. Try searching up the CreateThread() API.Brandon Asuncionhttps://www.blogger.com/profile/11452066894989028521noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-91352978488421869962009-07-16T21:57:24.073+02:002009-07-16T21:57:24.073+02:00That page compiles C++ for .net, and not natively....That page compiles C++ for .net, and not natively. Delphi 2009 compiles natively.<br /><br />If you would try a native C/C++ compiler it would beat C++ for .net.Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-67157124793434971882009-07-16T17:29:06.510+02:002009-07-16T17:29:06.510+02:00http://www.grimes.demon.co.uk/dotnet/man_unman.htm...http://www.grimes.demon.co.uk/dotnet/man_unman.htm<br /><br />this one compares C++ and C# and C# won! I also have seen a lot of other articles saying that managed code is on par or might be faster than unmanaged code. <br /><br />So it's pretty strange that Delphi beat C# to the punch... Something is simply not taken in account.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-47706705804076813032009-07-08T13:32:39.359+02:002009-07-08T13:32:39.359+02:00It is not correct to compare such different langua...It is not correct to compare such different languages as Delphi and PHP(Static Typing versus Dynamic Typing, Strong Typing versus Weak Typing). This is the dishonest comparison.<br /><br />In the tests given above, are compared the languages from different categories(native code versus byte code/JIT compiler output). Why not to compare Delphi and C++ (both uses native code)?<br /><br /><br />>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-1526513545474283792009-07-04T12:08:37.929+02:002009-07-04T12:08:37.929+02:00Unfortunately Delphi isn't listed at http://sh...Unfortunately Delphi isn't listed at http://shootout.alioth.debian.org but Free Pascal is there (and it does reasonably well IMHO)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-76921381185826371612009-06-30T18:29:30.414+02:002009-06-30T18:29:30.414+02:00Lars D > Comparing PHP to Delphi by benchmarkin...Lars D > <em>Comparing PHP to Delphi by benchmarking a C/C++ library function does not impress me.</em> <br /><br />But you do seem to be impressed by comparing Delphi to PHP on a task that is so obviously suited to the low-level programming available in a language like C - the odd thing is that Delphi isn't being compared to C or C++.<br /><br /><br />Incidentally, did you check that Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-75771253782100564302009-06-30T10:59:46.818+02:002009-06-30T10:59:46.818+02:00And, please, don't forget about OpenMP, it giv...And, please, don't forget about OpenMP, it gives linear speedup without any additional efforts :)<br /><br /> DWORD myavg1;<br /> stime = timeGetTime();<br />#pragma omp parallel for<br /> for (int cnt=0; cnt < 200; ++cnt) {<br /> int lmyavg1 = 0;<br /> for (int i=0; i < 1000000; ++i) {<br /> lmyavg1 += arrw[i];<br /> }<br /> myavg1 = lmyavg1;<br /> }<br /> etime = timeGetTime();<ksuboxhttps://www.blogger.com/profile/15943923768261993571noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-29567391685645169942009-06-30T09:03:54.641+02:002009-06-30T09:03:54.641+02:00Actually, I tried that. In Delphi, performance get...Actually, I tried that. In Delphi, performance gets slower if you try to substitute a for-loop with a while-loop...<br /><br />Delphi knows all kinds of for-loop optimizations, including reversing the order if the order doesn't matter, changing the loop variable to be 8 times bigger, arranging machine code instructions for optimal timing etc.<br /><br />You can observe the changes in loop Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-23724410790659988192009-06-30T08:34:09.817+02:002009-06-30T08:34:09.817+02:00Victor:
for j:=0 to length(arrw)-1 step 8 do
Wich ...Victor:<br />for j:=0 to length(arrw)-1 step 8 do<br />Wich version of Delphi do you use?<br /><br />OMG! I'm so sorry. That isn't Pascal, it's Basic!<br />for i = 0 to n step 8<br /> ..<br />next<br /><br />Well, I guess not all is bad about Basic either= :-)<br /><br />In Delphi you would have to use a while loop and increment the iterator yourself. Actually, it might be worth a Unknownhttps://www.blogger.com/profile/14818707587064445487noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-90767486386140654112009-06-30T05:10:15.182+02:002009-06-30T05:10:15.182+02:00Try this one:
http://test.tvsori.com/bench2.cpp - ...Try this one:<br />http://test.tvsori.com/bench2.cpp - veeeeery simple, strait & stupid implementation, easiest to read.<br />And executable (please check for viruses who knows what I have):<br />http://test.tvsori.com/Bench_intel_autovec_autoparr.exe<br /><br />Bench_intel_autovec_autoparr . exe<br /><br />Nothing to say more...ksuboxhttps://www.blogger.com/profile/15943923768261993571noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-83462384612329005602009-06-29T20:03:20.975+02:002009-06-29T20:03:20.975+02:00Isaac: I'm a big fan of php, but I also know i...Isaac: I'm a big fan of php, but I also know its limits. Comparing PHP to Delphi by benchmarking a C/C++ library function does not impress me.Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-39748266908298290792009-06-29T18:20:46.769+02:002009-06-29T18:20:46.769+02:00Instead of -
PHP was 1000-2500 times slower than ...Instead of -<br /><br /><em>PHP was 1000-2500 times slower than Delphi.</em> <br /><br />- the data now shows PHP was 8-1100 times slower, and I'll suggest that extreme range is down to using or ignoring what comes standard with PHP :-)<br /><br /><br />Lars D > <em>I know which language I would pick for writing a complex algorithm that needs to be fast with big amounts of data, and it'Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-11910361885924185832009-06-29T08:33:47.980+02:002009-06-29T08:33:47.980+02:00I've updated the spreadsheet to include links ...I've updated the spreadsheet to include links to the code which has been run to get the results.<br /><br />I've also updated with the latest php from Isaac, some new vbs and python and c# using a com object.Haldhttps://www.blogger.com/profile/10710656371495082395noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-61871445969238687182009-06-29T08:32:15.128+02:002009-06-29T08:32:15.128+02:00I've updated the spreadsheet to show which cod...I've updated the spreadsheet to show which codes has been tested to get the results.<br /><br />The latest php from Isaac is also put in, as is a vbs version, another python version and c# using a COM objectHaldhttps://www.blogger.com/profile/10710656371495082395noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-83073258313475410482009-06-27T17:41:00.254+02:002009-06-27T17:41:00.254+02:00If I understood the requirements correctly, that l...If I understood the requirements correctly, that last PHP script should also be the fastest PHP solution to "number of values = 42".<br /><br />Although it might be a tiny little bit faster for that problem to comment out one line<br /><br />// for ($i = 0; $i <= 100; $i++) { $sum += $c[$i] * $i; }Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-16194598646156207572009-06-27T08:01:21.579+02:002009-06-27T08:01:21.579+02:00Jesper, the latest PHP function, that does countin...Jesper, the latest PHP function, that does counting & averaging, is actually less than 600ms on my PC, so it should be around 300-400ms on your laptop. Would it be possible to publish the algorithms from the spreadsheet?Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-48776005323085592472009-06-27T02:02:25.837+02:002009-06-27T02:02:25.837+02:00If I understood the requirement correctly, here fo...If I understood the requirement correctly, here for completeness is PHP <strong>average for all 1,000,000*200 values</strong> <br /><br /><br />function secs() {<br /> list($usec, $sec) = explode(" ", microtime());<br /> return ((float)$usec + (float)$sec);<br />}<br /><br /><br />$n = 1000000;<br />$repeat = 200;<br /><br />srand();<br />$data = str_repeat("0",$n);<br />Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-79034753118826869322009-06-27T01:50:44.748+02:002009-06-27T01:50:44.748+02:00This comment has been removed by the author.Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-7592011471965300162009-06-27T00:28:41.041+02:002009-06-27T00:28:41.041+02:00Hald > PHP times updated with the secs function...Hald > <em>PHP times updated with the secs function. Time is 1.8 seconds</em> <br /><br />Pleased that worked for you; so ~36x times slower than the fastest.<br /><br />And I would guess the new program using count_chars is more like 0.8 seconds on your machine?Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-84269125983224080182009-06-26T21:44:43.538+02:002009-06-26T21:44:43.538+02:00PHP times updated with the secs function.
Time is...PHP times updated with the secs function.<br /><br />Time is 1.8 secondsHaldhttps://www.blogger.com/profile/10710656371495082395noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-67284394935624757942009-06-26T21:07:23.179+02:002009-06-26T21:07:23.179+02:00Victor:
for j:=0 to length(arrw)-1 step 8 do
Wich ...Victor:<br /><i>for j:=0 to length(arrw)-1 step 8 do</i><br />Wich version of Delphi do you use?Torbinsnoreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-53959797824478761082009-06-26T21:01:57.944+02:002009-06-26T21:01:57.944+02:00I also doubt that PHP
for ($i = 0; $i < $n; $...I also doubt that PHP <br /><br />for ($i = 0; $i < $n; $i++)<br /><br />is implemented in PHP so I don't see how <em>your point</em> applies to the comparisons you have been making?<br /><br /><br />This seems more "obvious" a solution than preg_match_all<br /><br />srand();<br />$data = str_repeat("0",1000000);<br />for ($i = 0; $i < 1000000; $i++) { $data[$i] = Isaac Gouyhttps://www.blogger.com/profile/02902123247585964087noreply@blogger.comtag:blogger.com,1999:blog-4434108347727659251.post-17166411014250597292009-06-26T20:33:35.188+02:002009-06-26T20:33:35.188+02:00"I very much doubt that preg_match_all is wri..."I very much doubt that preg_match_all is written in PHP." - totally my point.Lars Dhttps://www.blogger.com/profile/06217303713945608384noreply@blogger.com