2017 © Pedro Peláez
 

library php-benchmark

A simple PHP Benchmark class

image

alexgaal/php-benchmark

A simple PHP Benchmark class

  • Thursday, May 4, 2017
  • by alexgaal
  • Repository
  • 1 Watchers
  • 1 Stars
  • 233 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

php-benchmark

A simple PHP Benchmark class., (*1)

Example usage

Benchmark a function

``` php <?php $forBenchmark = Benchmark::time(function () { for ($i = 0; $i < 100; $i++) { // } });, (*2)

$whileBenchmark = Benchmark::time(function () { $i = 0; while ($i < 100) { $i++; } });, (*3)

echo $forBenchmark->compare($whileBenchmark);, (*4)


### Benchmark a block of code ``` php <?php $forBenchmark = Benchmark::begin(); for ($i = 0; $i < 100; $i++) { // } $forBenchmark->stop(); $whileBenchmark = Benchmark::begin(); $i = 0; while ($i < 100) { $i++; } $whileBenchmark->stop(); echo $forBenchmark->compare($whileBenchmark);

Nested benchmarks

``` php <?php $calculateBenchmark = Benchmark::begin(); for ($i = 0; $i < 1000; $i++) { pow($i, $i); }, (*5)

$databaseBenchmark = Benchmark::begin(); // do some random database stuff $databaseBenchmark->stop(); $calculateBenchmark->stop();, (*6)



## Function signature

$callback Closure A function which will be called in Benchmark::time() function. $iterations int Number of iterations of function call. $avg bool Returns average values of memory and time if true, otherwise will return accumulated values. Benchmark::time(\Closure $callback, int $iterations, bool $avg) ```, (*7)

The Versions

04/05 2017

dev-master

9999999-dev

A simple PHP Benchmark class

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Alexander Gaal

04/05 2017

v0.0.1

0.0.1.0

A simple PHP Benchmark class

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Alexander Gaal