PHP code example of mts7 / benchmarks

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

    

mts7 / benchmarks example snippets


$container = \MtsBenchmarks\Factory\ContainerFactory::create();

$samples = 5;
$iterations = 100;
$title = 'callable name';

$benchmark = $container->get(\MtsBenchmarks\Benchmark::class,
    [
        $container->get(\MtsBenchmarks\Helper\IncrementIntegerIterator::class, [$samples]),
        $container->get(\MtsBenchmarks\Helper\IncrementIntegerIterator::class, [$iterations]),
    ]
);

$results = $benchmark->run(['callable']);

$report = $container->get(\MtsBenchmarks\Report\ConsoleReport::class);

echo $report->generate($samples, $iterations, $title, $results);

$samples = 5;
$iterations = 100;
$title = 'callable name';

$benchmark = $container->get(\MtsBenchmarks\Benchmark::class,
    [
        $container->get(\MtsBenchmarks\Helper\IncrementIntegerIterator::class, [$samples]),
        $container->get(\MtsBenchmarks\Helper\IncrementIntegerIterator::class, [$iterations]),
    ]
);
$report = $container->get(\MtsBenchmarks\Report\ConsoleReport::class);

$output = $report->buildTitle($samples, $iterations, $title);
$output .= $report->buildHeaders($title);
$results = $benchmark->run(['callable']);
$output .= $report->buildResults($results);

echo $output;

// raw durations from executing the callable $iterations times per sample
$durations = $benchmark->buildSamples('callable');