The Little Guy Posted September 6, 2008 Share Posted September 6, 2008 Is there any speed difference between python and php? Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/ Share on other sites More sharing options...
The Little Guy Posted September 6, 2008 Author Share Posted September 6, 2008 OK, I ran 2 Scripts. PHP: <?php $p = 10000000; $t = 0; $s = microtime(true); for($n=0;$n < $p;$n++){ $t = md5($n + $n); $t = 0; } $e = microtime(true); echo $e-$s; ?> Python: #!/usr/bin/python import md5 from time import clock p = 10000000 n = 0 t = 0 start = clock() while n < p: t = n + n md5.new(str(n)).digest() n = n + 1 t = '' stop = clock() print "Content-type: text/html\n\n" print round(stop-start,4)[/coe] The final outputs (rounded to the nearest 100th): PHP: - 30.84 - 25.66 - 21.90 - 24.75 - 19.25 Python: - 23.89 - 23.25 - 23.46 - 23.44 - 23.45 Averages: PHP: 24.48 Python: 23.49 WOW, I really thought Python was going to win by a lot, since PHP's First round was almost 31. Guess I was wrong. Python does look like a more constant language though seeing that all the results stayed at 23, otherwise PHP just caches the values for faster speeds when ran multiple times. Any thoughts on this test? Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635190 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 My results: #PHPPython 143.6428.60 244.0827.66 343.7228.34 444.4527.81 544.0728.49 643.5127.97 743.5628.00 844.6028.52 944.6627.86 1044.2827.80 Avg:44.0628.11 Note no reduction in time for consecutive PHP executions. It's run on Vista Business, Intel CoreDuo T9500 Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635228 Share on other sites More sharing options...
The Little Guy Posted September 6, 2008 Author Share Posted September 6, 2008 I assume you copied and pasted my scripts correct? If so, did you have a procedure of how you ran it? Such as... run PHP 10 times, then python 10 times or run php 1 time then python 1 time, 10 times I did the second way. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635239 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 It was 10 times PHP then 10 times Python Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635261 Share on other sites More sharing options...
Daniel0 Posted September 6, 2008 Share Posted September 6, 2008 FYI, the second time you run the python script it should be faster because it caches the byte code so it doesn't have to be interpreted again unless the source file has been changed. Those are the .pyc files you'll see. You can achieve the same effect with an opcode cache for PHP such as APC as well of course. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635353 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 Not much source here to interpret though. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635394 Share on other sites More sharing options...
Daniel0 Posted September 6, 2008 Share Posted September 6, 2008 No, but on a large scale project with many files, having an opcode cache can improve the performance considerably. Besides, if we say that we run a small script like the above ones a thousand times then you should see a noticeable difference by saving 999 interpretations. A site like The Pirate Bay gets many thousands of hits each minute so caching is crucial for system performance regardless of the script's complexity. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635408 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 In those cases yes. For the purpose of this benchmark, bytecode caching has probably a negligible influence (unless we indeed try to run it several hundreds of times). Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635419 Share on other sites More sharing options...
Daniel0 Posted September 6, 2008 Share Posted September 6, 2008 The issue in question was whether Python was faster than PHP. I suppose this is for real-world usage instead of tiny benchmarks only covering a confined amount of structures and features of each language in a sample script that wouldn't be used otherwise. The only thing tested in the above benchmark was loops, integer addition and the MD5 algorithm. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635427 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 Only thing it proves is that Python loops faster than PHP on my PC Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635430 Share on other sites More sharing options...
corbin Posted September 7, 2008 Share Posted September 7, 2008 Python is almost 3 times slower on my box... Like already mentioned, this is a horrible comparison. For example, what if the md5 function is just super slow on my computer under python? Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635666 Share on other sites More sharing options...
The Little Guy Posted September 7, 2008 Author Share Posted September 7, 2008 what would be a good comparison? I was running my scripts on a shared web server. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635703 Share on other sites More sharing options...
corbin Posted September 7, 2008 Share Posted September 7, 2008 I don't think there is a fair comparison that isn't long and drawn out. Basically you would have to create the same application in both languages, making sure everything is handled the same. Even then though, it could be inaccurate, although it would give a real world reading. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635862 Share on other sites More sharing options...
448191 Posted September 7, 2008 Share Posted September 7, 2008 Those benchmarks are useless. All you are testing is the speed of creating MD5 hashes. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635922 Share on other sites More sharing options...
corbin Posted September 7, 2008 Share Posted September 7, 2008 Python is almost 3 times slower on my box... Like already mentioned, this is a horrible comparison. For example, what if the md5 function is just super slow on my computer under python? I just realized what I typed earlier, and I want to reword that to say: Python is almost 3 times slower on my box with this script... Like already mentioned, this is a horrible comparison. For example, what if the md5 function is just super slow on my computer under python? Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-635938 Share on other sites More sharing options...
The Little Guy Posted September 8, 2008 Author Share Posted September 8, 2008 I just wrote a mysql query, I did the exact same thing in Python as PHP, and the query took this long: Python - 0.01 PHP - 0.075 Using SQL_CALC_FOUND_ROWS, it would have returned: 3,649 rows, otherwise with the limit it returned 5 rows. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-636271 Share on other sites More sharing options...
corbin Posted September 8, 2008 Share Posted September 8, 2008 Once again, all that proves is that feature a is faster in language b than in language c. That doesn't make language b better than c or the other way around x.x. This thread is seeming pointless to me ;p. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-636298 Share on other sites More sharing options...
The Little Guy Posted September 8, 2008 Author Share Posted September 8, 2008 I never said PHP was faster than Python. First I was asking, then testing. I also got some good replies, such as yours: all that proves is that feature a is faster in language b than in language c Ill mark this Solved. If anyone wants to continue, be my guest. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-636601 Share on other sites More sharing options...
Mchl Posted September 8, 2008 Share Posted September 8, 2008 If you like doing such things, then I'd love to see some comparison between libmysql (default library that connects PHP to MySQL) and mysqlnd (new native driver) Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-636643 Share on other sites More sharing options...
corbin Posted September 9, 2008 Share Posted September 9, 2008 http://blog.felho.hu/what-is-new-in-php-53-part-3-mysqlnd.html No idea if that's accurate/true or not, but interesting read (found through Google). It links to this as a benchmark: http://blog.ulf-wendel.de/?p=138 Once again, I can't/won't vouch for it being accurate/true. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-637084 Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 Once again, I can't/won't vouch for it being accurate/true. Since mysqlnd is not a finished product yet (or so I understand) then of course all benchmarks have to be taken with a grain of salt. Nevertheless it's nice to see some. Thanks for the links. Link to comment https://forums.phpfreaks.com/topic/122973-solved-php-vs-python/#findComment-637273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.