<?php namespace Phpreboot\performance\basic\quote; include_once 'vendor/autoload.php'; use Phpreboot\Stopwatch\StopWatch; // Create an instance of StopWatch $stopWatch = new StopWatch(); // Initialize the watches. $stopWatch->addWatches(["single", "double"]); $stopWatch->start("single"); $nameSingleQuote = 'Kapil Sharma'; $stopWatch->stop("single"); $stopWatch->start("double"); $nameDoubleQuote = "Kapil Sharma"; $stopWatch->stop("double"); printf("Single quotes took %f seconds \n", $stopWatch->getTime("single")); printf("Double quotes took %f seconds \n", $stopWatch->getTime("double"));
* * (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"; use Phpreboot\Stopwatch\StopWatch; // Create an instance of StopWatch $stopWatch = new StopWatch(); // Start the watch to start timer, $stopWatch->start(); $iteration = 0; for ($i = 0; $i < 10000; $i++) { for ($j = 0; $j < 10000; $j++) { $iteration++; } } // Stop the watch. $stopWatch->stop(); // By default, it will return time in seconds $time = $stopWatch->getTime(); printf("Time taken for %d iterations was %f seconds.\n", $iteration, $time);
/** * @group Phpreboot_Stopwatch_StopWatch_stop */ public function testNonExistingStopWatchCanNotBeStopped() { $this->assertFalse($this->stopWatch->stop('nonExistingWatch')); }