PHP Classes

File: example/simplewatch.php

Recommend this page to a friend!
  Classes of Kapil Sharma   PHP Reboot Stop Watch   example/simplewatch.php   Download  
File: example/simplewatch.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Reboot Stop Watch
Record time PHP blocks take to execute
Author: By
Last change: Fixing symfony insight issues
Date: 6 years ago
Size: 1,092 bytes


Class file image Download

 * This file is part of the PHPReboot/Stopwatch package.
 * (c) Kapil Sharma <>
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.

 * This example shows simple use of Stopwatch. For simple use, we need just four steps:
 * - Create instance of StopWatch,
 * - Call `start()` method to start the timer,
 * - Call `stop()` method to stop the watch, and
 * - Call `getTime()` method to get the time between start and stop.

// Load Composer auto loader
require_once "../vendor/autoload.php";


// Create an instance of StopWatch
$stopWatch = new StopWatch();

// Start the watch to start timer,

$iteration = 0;

for (
$i = 0; $i < 10000; $i++) {
    for (
$j = 0; $j < 10000; $j++) {

// Stop the watch.

// By default, it will return time in seconds
$time = $stopWatch->getTime();

printf("Time taken for %d iterations was %f seconds.\n", $iteration, $time);