PHP code example of geocurly / easy-benchmark
1. Go to this page and download the library: Download geocurly/easy-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/ */
geocurly / easy-benchmark example snippets
use EasyBenchmark\EasyBenchmark;
i++) {
$arrays[] = range(0, 1000);
}
$test = [
"sequence merge" => function () use($arrays) {
$arr = [];
foreach ($arrays as $array) {
$arr = array_merge($arr, $array);
}
},
"merge unpacked array" => function () use($arrays) {
array_merge(...$arrays);
}
];
foreach (EasyBenchmark::run($test, 100) as $result) {
echo (string) $result . "\n";
}
/*
* Output:
* Name: sequence merge. Iteration 100. Execution time 8.31734 ms
* Name: merge unpacked array. Iteration 100. Execution time 0.17974 ms.
*/
use EasyBenchmark\EasyBenchmark;
use EasyBenchmark\Result;
c function push($value): void
{
$this->storage[] = $value;
}
};
$testFunctions = [
"testMemoryUsage" => static function (Result $result) use($storage) {
$storage->push(random_bytes(random_int(100000, 200000)));
$result->setMemory(memory_get_usage());
}
];
/*
* There is we set third input argument as "false" to get every iteration result
*/
foreach (EasyBenchmark::run($testFunctions, 10, false) as $result) {
echo "Iteration: {$result->getIter()}. Memory: {$result->humanReadableMemory()} \n";
}
/*
* Output:
* Iteration: 1. Memory: 1,04 МБ
* Iteration: 2. Memory: 1,20 МБ
* Iteration: 3. Memory: 1,35 МБ
* Iteration: 4. Memory: 1,46 МБ
* Iteration: 5. Memory: 1,63 МБ
* Iteration: 6. Memory: 1,79 МБ
* Iteration: 7. Memory: 1,90 МБ
* Iteration: 8. Memory: 2,07 МБ
* Iteration: 9. Memory: 2,18 МБ
* Iteration: 10. Memory: 2,35 МБ
*/