Core PHP

A Simple Timer

This program demonstrates how to use a simple timer to time a piece of code in PHP.

SimpleTimer.php

<?php
  $fStartTime = microtime(true);

  // Sleep for 2 seconds. The time is specified in microseconds.
  usleep(2000000);

  $fEndTime = microtime(true);
  $fElaspedTime = $fEndTime - $fStartTime;

  echo "$fElaspedTime seconds have elapsed.\n";
?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.