Skip to content

Instantly share code, notes, and snippets.

@stojg
Created February 1, 2011 14:39
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 stojg/805937 to your computer and use it in GitHub Desktop.
Save stojg/805937 to your computer and use it in GitHub Desktop.
PHP5 Utility timer for fast benchmarks of code
<?php
class Timer {
protected static $start_time = 0.00;
protected static $total_time = 0.00;
public static function start() {
self::$start_time = microtime(true);
}
public static function stop() {
$time_end = microtime(true);
$end_time = $time_end - self::$start_time;
self::$total_time = $end_time + self::$total_time;
return sprintf("%.3fs (%.3fs total)" ,$end_time, self::$total_time );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment