Skip to content

Instantly share code, notes, and snippets.

@peterlozano
Created February 8, 2011 11:01
Show Gist options
  • Save peterlozano/816273 to your computer and use it in GitHub Desktop.
Save peterlozano/816273 to your computer and use it in GitHub Desktop.
Measure the time spent in a piece of code. Extracted from Drupal database layer.
<?php
list($usec, $sec) = explode(' ', microtime());
$timer = (float)$usec + (float)$sec;
//
// YOUR CODE HERE
//
list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
// Diff contains a float in seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment