Created
October 26, 2015 23:34
-
-
Save kamermans/04d3e557efca29bf2123 to your computer and use it in GitHub Desktop.
PHP time() vs microtime() vs microtime(true) benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PHP | |
-------------------------------------------------------------- | |
Total Iterations: 10,000,000 | |
time(): 0.73976612091064 seconds (13,517,785/sec) | |
microtime(): 4.2245488166809 seconds (2,367,116/sec) | |
microtime(true): 1.2555038928986 seconds (7,964,929/sec) | |
HHVM | |
-------------------------------------------------------------- | |
Total Iterations: 10,000,000 | |
time(): 0.081642866134644 seconds (122,484,675/sec) | |
microtime(): 4.1530148983002 seconds (2,407,889/sec) | |
microtime(true): 0.37003302574158 seconds (27,024,614/sec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$total = 10000000; | |
echo "Total Iterations: ".number_format($total)."\n"; | |
echo "time(): "; | |
$start = microtime(true); | |
for ($i=0; $i<$total; $i++) { | |
$time = time(); | |
} | |
$dur = microtime(true) - $start; | |
$perf = number_format(floor($total / $dur)); | |
echo "$dur seconds ($perf/sec)\n"; | |
echo "microtime(): "; | |
$start = microtime(true); | |
for ($i=0; $i<$total; $i++) { | |
$time = microtime(); | |
} | |
$dur = microtime(true) - $start; | |
$perf = number_format(floor($total / $dur)); | |
echo "$dur seconds ($perf/sec)\n"; | |
echo "microtime(true): "; | |
$start = microtime(true); | |
for ($i=0; $i<$total; $i++) { | |
$time = microtime(true); | |
} | |
$dur = microtime(true) - $start; | |
$perf = number_format(floor($total / $dur)); | |
echo "$dur seconds ($perf/sec)\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
here is my results in php 8.1.3
Round 1:
Total Iterations: 10,000,000
time(): 0.65436005592346 seconds (15,282,106/sec)
microtime(): 4.5953159332275 seconds (2,176,128/sec)
microtime(true): 0.67478799819946 seconds (14,819,469/sec)
Round 2
Total Iterations: 10,000,000
time(): 0.61929297447205 seconds (16,147,446/sec)
microtime(): 4.6143391132355 seconds (2,167,157/sec)
microtime(true): 0.6597728729248 seconds (15,156,731/sec)
Round 3
Total Iterations: 10,000,000
time(): 0.68782711029053 seconds (14,538,537/sec)
microtime(): 4.6785700321198 seconds (2,137,405/sec)
microtime(true): 0.73401689529419 seconds (13,623,664/sec)