PHP code example of alexgaal / php-benchmark

1. Go to this page and download the library: Download alexgaal/php-benchmark library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexgaal / php-benchmark example snippets

 php

$forBenchmark = Benchmark::time(function () {
    for ($i = 0; $i < 100; $i++) {
        //
    }
});

$whileBenchmark = Benchmark::time(function () {
    $i = 0;
    while ($i < 100) {
        $i++;
    }
});

echo $forBenchmark->compare($whileBenchmark);
 php

$forBenchmark = Benchmark::begin();
for ($i = 0; $i < 100; $i++) {
    //
}
$forBenchmark->stop();

$whileBenchmark = Benchmark::begin();
$i = 0;
while ($i < 100) {
    $i++;
}
$whileBenchmark->stop();

echo $forBenchmark->compare($whileBenchmark);
 php

$calculateBenchmark = Benchmark::begin();
for ($i = 0; $i < 1000; $i++) {
    pow($i, $i);
}

$databaseBenchmark = Benchmark::begin();
// do some random database stuff
$databaseBenchmark->stop();
$calculateBenchmark->stop();