Last active
August 29, 2015 14:04
-
-
Save ppKrauss/4cd3c9a5f7cec89be68e to your computer and use it in GitHub Desktop.
Simple benchmark-base for use in any simple benchmarking task
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 | |
/** | |
* Simple benchmark-base for use in any simple benchmarking task. | |
* Use at terminal as $php benchmark_base.php | |
* For more complex or memory usage, see | |
* http://php.net/manual/en/ref.xhprof.php | |
* http://php.net/manual/en/function.set-time-limit.php | |
* http://php.net/manual/en/features.gc.performance-considerations.php | |
* From https://gist.github.com/ppKrauss/4cd3c9a5f7cec89be68e | |
*/ | |
// CONFIGURATIONS: | |
$BENCH_PRECICION = 3; // number of digits after the decimal point of secounds counter. | |
$BENCH_N = 5; // number of loops in the execution test. | |
$time_start = microtime(true); // unix-time-stamp in seconds, with microseconds. | |
for($BENCH_I=0; $BENCH_I<$BENCH_N; $BENCH_I++): | |
// #### !!COPY/PASTE YOR CODE HERE!! #### | |
sleep(1); // test delay of 1 second | |
// #### #### #### #### #### #### #### #### | |
endfor; | |
// REPORT: | |
$time_diff = microtime(true) - (float) $time_start; // ellapsed time in seconds | |
$time_diff_all = round($time_diff,$BENCH_PRECICION); // seconds | |
$time_diff_each = $time_diff/$BENCH_N; // seconds | |
echo "\nExecution total time of $BENCH_N loops: $time_diff_all seconds"; | |
echo "\nAveraged execution time of each loop: $time_diff_each seconds\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment