PHP code example of alecrabbit / php-simple-profiler

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

    

alecrabbit / php-simple-profiler example snippets


use AlecRabbit\Tools\BenchmarkSymfonyProgressBar;

00);
$benchmark
    ->addFunction('hrtime', true); 
$benchmark
    ->addFunction('microtime', true);
echo $benchmark->run()->noReturns()->report() . PHP_EOL;
echo $benchmark->stat() . PHP_EOL;

$b = new BenchmarkSymfonyPB(900000) // with Symfony Progress bar, 900000 measurments

$func = function (array $a) {
    return array_sum($a);
};

$a = [1, 2, 3];

$b->addFunction('call_user_func', $func, $a);

$b->addFunction($func, $a);

$b->run();

$report = $b->report(); // you can get report object and use data from it 
echo $report . PHP_EOL; // or you can print it by default formatter
echo $b->stat() . PHP_EOL;

$profiler = new Profiler();

for ($i = 0; $i < 100; $i++) {
    $profiler->counter()->bump();
    someOperation();
    $profiler->timer()->check();
}

echo $profiler->report() . PHP_EOL;
bash
composer 

Results:
Benchmark:
1.  219.3ns (  0.00%) $func(array) $func(...$args)
2.  287.4ns ( 31.09%) call_user_func(array) \call_user_func($func, ...$args)
All returns are equal: 
integer(6) 
Benchmarked: 2 
Memory: 0.87MB(0.91MB) Real: 2.00MB(2.00MB)

Done in: 1.1s