2017 © Pedro Peláez
 

library phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

image

phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  • Friday, August 4, 2017
  • by vic
  • Repository
  • 8 Watchers
  • 82 Stars
  • 5,097 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

PHP-Benchmark

This library contains classes used to compare algorithms and benchmark your application., (*1)

Benchmarking

Setup

  1. Either download the library to your server or install it in your project using composer
  2. Include the file init.php in the very beginning of the first file that receives the request to your application (this is usually index.php). Then load the address of your website in the browser with the query parameters php-benchmark-test=1 and the benchmark data will be displayed in the upper left corner of your website.

Becnhmark 1, (*2)

Taking snapshots

If you want to take snapshots from the benchmark data during the request you may do so by adding the following code., (*3)

 \PHPBenchmark\Monitor::instance()->snapshot('Bootstrap finished');
````

Inserting some snapshots in the source code of WordPress gave me the following benchmark data

![Becnhmark 1](http://victorjonsson.github.com/PHP-Benchmark/sc-2.png)

## Comparing algorithms

### Setup (composer)

Add the dependency "phpbenchmark/phpbenchmark" to composer.json and your'e set to go.

### Example code

```php

require __DIR__.'/vendor/autoload.php';

use \PHPBenchmark\testing\FunctionComparison;

function xrange($start, $limit, $step = 1) {
    if ($start < $limit) {
        if ($step <= 0) {
            throw new LogicException('Step must be +ve');
        }

        for ($i = $start; $i <= $limit; $i += $step) {
            yield $i;
        }
    } else {
        if ($step >= 0) {
            throw new LogicException('Step must be -ve');
        }

        for ($i = $start; $i >= $limit; $i += $step) {
            yield $i;
        }
    }
}

FunctionComparison::load()
    ->addFunction('using array', function () {
        foreach (range(1, 9, 2) as $number) {}
    })
    ->addFunction('using generator', function () {
        foreach (xrange(1, 9, 2) as $number) {}
    })
    ->exec();

Load a file having this code in the browser, or call it via command line, and you will find out that generators consumes less memory but is at the same time considerbly slower., (*4)

You can also call ->run() to get hold of an object representing the results of the comparison test. Read more in the docs., (*5)

The Versions

04/08 2017

dev-master

9999999-dev http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

The Development Requires

test benchmark performance profiler

16/03 2017

1.1.4

1.1.4.0 http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

The Development Requires

test benchmark performance profiler

11/02 2016

1.1.3

1.1.3.0 http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

The Development Requires

test benchmark performance profiler

06/02 2016

1.1.0

1.1.0.0 http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

The Development Requires

test benchmark performance profiler

02/11 2015

1.0.2

1.0.2.0 http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

test benchmark performance profiler

18/05 2013

1.0.1

1.0.1.0 http://victorjonsson.github.com/PHP-Benchmark/

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

  Sources   Download

MIT

The Requires

 

test benchmark performance profiler