Skip to content

Instantly share code, notes, and snippets.

@ppKrauss
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppKrauss/4cd3c9a5f7cec89be68e to your computer and use it in GitHub Desktop.
Save ppKrauss/4cd3c9a5f7cec89be68e to your computer and use it in GitHub Desktop.
Simple benchmark-base for use in any simple benchmarking task
<?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