PHP code example of macocci7 / php-benchmark
1. Go to this page and download the library: Download macocci7/php-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/ */
macocci7 / php-benchmark example snippets
ci7\PhpBenchmark\Benchmark;
Benchmark::code(
name: 'str_starts_with()',
callback: fn () => str_starts_with('GPSAltitude', 'GPS'),
iteration: 10000
);
Benchmark::codes(
callbacks: [
'str_starts_with()' => fn () => str_starts_with('GPSAltitude', 'GPS'),
'strpos()' => fn () => strpos('GPSAltitude', 'GPS'),
'strpbrk()' => fn () => strpbrk('GPSAltitude', 'GPS'),
'strncmp()' => fn () => 0 === strncmp('GPSAltitude', 'GPS', 3),
'strstr()' => fn () => strstr('GPSAltitude', 'GPS'),
'preg_match()' => fn () => preg_match('/^GPS/', 'GPSAltitude'),
'strcmp() + substr()' => fn () => 0 === strcmp(substr('GPSAltitude', 0, 3), 'GPS'),
'substr_compare()' => fn () => 0 === substr_compare('GPSAltitude', 'GPS', 0, 3),
],
iteration: 10000, // default: 1
sortOrder: "", // without sorting (default)
//sortOrder: "asc", // by time
//sortOrder: "desc",
);
bash
composer