예제 #1
0
 public function test_configure_stopwatch_and_test_5_milliseconds_and_print_milliseconds()
 {
     Stopwatch::configure(['timeUnit' => TimeUnits::MILLISECONDS]);
     Stopwatch::start();
     // Sleep 0.005 second
     usleep(5000);
     $total = Stopwatch::stop();
     $this->assertTrue($total > 5 && $total < 50);
 }
예제 #2
0
<?php

include '../vendor/autoload.php';
use Joruro\Enum\TimeUnits;
use Joruro\Stopwatch\Stopwatch;
$attempts = 2;
$counter = 5;
Stopwatch::start();
for ($j = 0; $j < $attempts; $j++) {
    Stopwatch::start();
    for ($i = 0; $i < $counter; $i++) {
        sleep(1);
    }
    $time = Stopwatch::stop(TimeUnits::SECONDS);
    echo "A foreach of {$counter} loops took approximately {$time} seconds\n";
}
$time = Stopwatch::stop(TimeUnits::SECONDS);
echo "{$attempts} attempts foreach of {$counter} loops took approximately {$time} seconds\n";
exit(0);