Skip to content

Instantly share code, notes, and snippets.

@docteurklein
Last active September 18, 2018 12:57
Show Gist options
  • Save docteurklein/534fc94a93e654d76a9c7e377aa5c07d to your computer and use it in GitHub Desktop.
Save docteurklein/534fc94a93e654d76a9c7e377aa5c07d to your computer and use it in GitHub Desktop.
<?php
$num = floatval($argv[1] ?? '1e6');
echo "iterations: $num\n";
function noop() {
}
$start = microtime(true);
printf("starting raw at:\t\t%.3F s\n", $start);
for ($i=0; $i < $num; $i++) {
noop();
}
$duration = microtime(true) - $start;
tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU);
$start_p = microtime(true);
printf("starting profiling at: \t\t%.3F s\n", $start_p);
for ($i=0; $i < $num; $i++) {
noop();
}
$duration_p = microtime(true) - $start_p;
tideways_xhprof_disable();
printf("raw:\t\t%d µs\n", $duration * 1e6);
printf("profiler:\t%d µs\n", $duration_p * 1e6);
printf("total overhead:\t%d µs (x%.2F)\n", ($duration_p - $duration) * 1e6, $duration_p / $duration);
printf("avg overhead:\t%.3F µs\n", (($duration_p - $duration) / $num) * 1e6);
@docteurklein
Copy link
Author


 % php -d zend_extension=opcache -d opcache.enable_cli=1 -n -d extension=$HOME/work/tideways/php-xhprof-extension/modules/tideways_xhprof.so -f example/overhead.php 1e6
iterations: 1000000
starting raw at:                1537275406.170 s
starting profiling at:          1537275406.177 s
raw:            6654 µs
profiler:       5944 µs
total overhead: -710 µs (x0.89)
avg overhead:   -0.001 µs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment