<?php require __DIR__ . "/../app/Loader.php"; $bench = new \Smuuf\Phpcb\PhpBenchmark(); define("FILENAME", "c:\\some\very\\hyper complex\file_path\\image.png"); $bench->addBench(function () { $ext = substr(strrchr(FILENAME, '.'), 1); }); $bench->addBench(function () { $ext = end(explode('.', FILENAME)); }); $bench->addBench(function () { $ext = substr(FILENAME, strrpos(FILENAME, '.') + 1); }); $bench->addBench(function () { $ext = preg_replace('/^.*\\.([^.]+)$/D', '$1', FILENAME); }); $bench->addBench(function () { $exts = preg_split("@[/\\.]@", FILENAME); $ext = end($exts); }); $bench->addBench(function () { $ext = pathinfo(FILENAME, PATHINFO_EXTENSION); }); $bench->run();
<?php require __DIR__ . "/../app/Loader.php"; $bench = new \Smuuf\Phpcb\PhpBenchmark(); $bench->addBench(function () { // Do stuff some way... }); $bench->addBench(function () { // Do stuff some other way... }); $bench->addBench(function () { // Do stuff some totally other way... }); // Add more benchmarks... // Run the benchmark (with default number of iterations) $bench->run();
<?php require __DIR__ . "/../app/Loader.php"; $bench = new \Smuuf\Phpcb\PhpBenchmark(); const COUNT = 100; $bench->addBench(function () { for ($i = 1; $i <= COUNT; $i++) { } }); $bench->addBench(function () { for ($i = COUNT; $i > 0; $i--) { } }); $bench->addBench(function () { for ($i = COUNT; $i--;) { } }); $bench->addBench(function () { for ($i = -COUNT; $i++;) { } }); $bench->run();
<?php require __DIR__ . "/../app/Loader.php"; $bench = new \Smuuf\Phpcb\PhpBenchmark(); // Set up everything we need. $variables = []; $variables[] = null; $variables[] = ''; $variables[] = '0'; $variables[] = 0; $bench->addBench(function () use($variables) { foreach ($variables as $v) { empty($v); } }); $bench->addBench(function () use($variables) { foreach ($variables as $v) { $v == 0; } }); $bench->addBench(function () use($variables) { foreach ($variables as $v) { !$v; } }); // Run the benchmark (with default number of iterations) $bench->run();
<?php require __DIR__ . "/../app/Loader.php"; $bench = new \Smuuf\Phpcb\PhpBenchmark(); $bench->addBench(function () { usleep(10000); }); $bench->addBench(function () { usleep(5000); }); $bench->addBench(function () { usleep(2500); }); $bench->addBench(function () { usleep(500); }); $bench->addBench(function () { usleep(100); }); $bench->addBench(function () { usleep(20000); }); $bench->run(100);