array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'de', ), 'this' => array ( 0 => 'hrtime.example.basic.php', 1 => 'Basic usage', ), 'up' => array ( 0 => 'hrtime.examples.php', 1 => 'Beispiele', ), 'prev' => array ( 0 => 'hrtime.examples.php', 1 => 'Beispiele', ), 'next' => array ( 0 => 'class.hrtime-performancecounter.php', 1 => 'HRTime\\PerformanceCounter', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/hrtime/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
The example illustrates the basic StopWatch class usage
Beispiel #1 Measure several code blocks execution and get the total
<?php
$c = new HRTime\StopWatch;
$c->start();
/* measure this code block execution */
for ($i = 0; $i < 1024*1024; $i++);
$c->stop();
$elapsed0 = $c->getLastElapsedTime(HRTime\Unit::NANOSECOND);
/* measurement is not running here*/
for ($i = 0; $i < 1024*1024; $i++);
$c->start();
/* measure this code block execution */
for ($i = 0; $i < 1024*1024; $i++);
$c->stop();
$elapsed1 = $c->getLastElapsedTime(HRTime\Unit::NANOSECOND);
$elapsed_total = $c->getElapsedTime(HRTime\Unit::NANOSECOND);
?>