PHP code example of freezemage / benchmark

1. Go to this page and download the library: Download freezemage/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/ */

    

freezemage / benchmark example snippets


use Freezemage\Benchmark\ResultSet;
use Freezemage\Benchmark\Runner;

$runner = new Runner();

$runner->iterations(5);

$find = static fn (array $parameters): bool => in_array(1, $parameters);

// With static parameters
$runner->parameters([1, 2, 3]);
$result = $runner->evaluate($find);

// With dynamic parameters (will be regenerated on each iteration)
$runner->dataProvider(static function (): array {
    $result = [];
    for ($i = 0; $i < 10; $i += 1) {
        $result[] = rand(0, 10);
    }
    return $result;
});
$result = $runner->evaluate($find);

// Output one
print $result->prettyPrint();

// Output multiple
$set = new ResultSet();
print $set->append('Run 1', $result)->prettyPrint(); // append each evaluate() result.