byster.net— PHP has a lot of functions that produce identical results (eg. ereg vs preg_match). Ever wondered which ones are fastest? Use the right ones and speed up your code.
May 20, 2006View in Crawl 4
First of all I don't know why ywong is so hostile to the idea of speeding up code. When you do it regularly it doesn't slow down development time.Secondly... PHP 4 is like twice as fast as PHP 5. What the hell is up with that? What ever happened to speed being their number one priority?
I thought the article was going to compare new PHP5 functions versus the PHP4 methods, like file_put_contents vs. fopen, fwrite, fclose. Misleading, and disappointing; no Digg.
I recently profilled a class I was working on using PEAR benchmark, I'm running PHP5.1, I switched between while(list(var,var)=each(var)) { ... } and foreach() for the loops in the code.The results were consistently faster when using while(list()=each()) than foreach(), although in the milliseconds, but its surprising that that result is different here, I wonder whats causing the difference.
ereg is NOT the same as preg_match; PCRE is quite an improvement (or so some would say) over the 'classic' regexp.And the first comparison really isn't right, since $i isn't initialised in the second example.
Maybe I am missing something, but the "faster" column numbers are not consistent throughout the benchmark.In the first few benchmarks, we see that a multiplier greater than 1.0 signifies a faster process. But if you scroll down to some of the later benchmarks (the random number generator is a good example), values greater than 1.0 seem to show that process is slower.If you are going to publish benchmarks, it helps if the meanings of your numbers are consistent throughout.
very nice page, i've got some code to go edit now.but i did have an issue wiht the "file vs file_get_content vs fread" test.its not fair.file loads the data into an array by line.file_get loads the whole file as 1 big string.BIG difference in work and effect,file_get is just a pretty wrapper for open, fread, close anyway.
Closed AccountMay 21, 2006
First of all I don't know why ywong is so hostile to the idea of speeding up code. When you do it regularly it doesn't slow down development time.Secondly... PHP 4 is like twice as fast as PHP 5. What the hell is up with that? What ever happened to speed being their number one priority?
samuellameMay 22, 2006
I thought the article was going to compare new PHP5 functions versus the PHP4 methods, like file_put_contents vs. fopen, fwrite, fclose. Misleading, and disappointing; no Digg.
hunchbackMay 22, 2006
I recently profilled a class I was working on using PEAR benchmark, I'm running PHP5.1, I switched between while(list(var,var)=each(var)) { ... } and foreach() for the loops in the code.The results were consistently faster when using while(list()=each()) than foreach(), although in the milliseconds, but its surprising that that result is different here, I wonder whats causing the difference.
veraconMay 22, 2006
ereg is NOT the same as preg_match; PCRE is quite an improvement (or so some would say) over the 'classic' regexp.And the first comparison really isn't right, since $i isn't initialised in the second example.
alarionMay 22, 2006
Maybe I am missing something, but the "faster" column numbers are not consistent throughout the benchmark.In the first few benchmarks, we see that a multiplier greater than 1.0 signifies a faster process. But if you scroll down to some of the later benchmarks (the random number generator is a good example), values greater than 1.0 seem to show that process is slower.If you are going to publish benchmarks, it helps if the meanings of your numbers are consistent throughout.
uberfuzzyMay 24, 2006
very nice page, i've got some code to go edit now.but i did have an issue wiht the "file vs file_get_content vs fread" test.its not fair.file loads the data into an array by line.file_get loads the whole file as 1 big string.BIG difference in work and effect,file_get is just a pretty wrapper for open, fread, close anyway.