Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created November 18, 2011 20:06
Show Gist options
  • Save xeoncross/1377596 to your computer and use it in GitHub Desktop.
Save xeoncross/1377596 to your computer and use it in GitHub Desktop.
Simple PHP benchmark class
<?php
define('SYSTEM_START_TIME', microtime(TRUE));
define('SYSTEM_START_MEMORY', memory_get_usage());
register_shutdown_function('_usage');
function _usage()
{
if(PHP_SAPI !== 'cli')
{
print '<div style="font-size: 14px; border: 1px solid #ddd; background: #fff; padding: 1em; margin: 1em;">';
}
print round(microtime(TRUE) - SYSTEM_START_TIME, 6). " ms<br />\n";
print number_format(memory_get_usage() - SYSTEM_START_MEMORY). " bytes<br />\n";
print number_format(memory_get_usage()) ." bytes (process)<br />\n";
print number_format(memory_get_peak_usage()). " bytes (peak process)<br />\n";
print "\n<pre>\n". print_r(get_included_files(), TRUE) . "</pre>\n";
if(PHP_SAPI !== 'cli')
{
print '</div>';
}
print "\n";
}
// Usage: require('benchmark.php');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment