PHP code example of serhiikorniushov / micro-bench

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

    

serhiikorniushov / micro-bench example snippets



erhiiKorniushov\MicroBench\MicroBench;
// Start the benchmark
$benchmark = (new SerhiiKorniushov\MicroBench\MicroBench)->start();
// Code to benchmark
for ($i = 0; $i < 100000; $i++) {
// Some operation
$a = $i * 2;
}
// Get elapsed microtime time in human-readable format
$benchmark->finish()->getElapsedMicroTimeReadable();
// OR
// Finish the benchmark
$benchmark->finish();
// Get the report
$report = $benchmark->getReport();
// Output the results
echo "Elapsed time: " . $benchmark->getElapsedMicroTimeReadable() . "\n";
echo "Elapsed time (seconds): " . $report['elapsed']['microtime'] . " s\n";
echo "Memory usage: " . $report['elapsed']['memory_usage'] . " bytes\n";
echo "Memory peak usage: " . $report['elapsed']['memory_peak_usage'] . " bytes\n";
// Print the full report (optional)
// print_r($report);