nochso/benchmark

Benchmark with reliable results

0.5.3 2016-04-18 21:43 UTC

This package is not auto-updated.

Last update: 2024-04-23 01:10:11 UTC


README

Latest Stable Version License

nochso/benchmark creates pretty HTML benchmarks from any closures you supply:

  • Generate HTML reports including Github flavoured Markdown
  • Reliably compare different algorithms
  • Run tests for a minimum amount of time to ensure stable results

View an example report

View the API documentation

Installation

  1. Install composer on Linux / Unix / OSX or Windows

  2. Require this package via composer:

    composer require nochso/benchmark

Usage

Have a look at the example reports.

A very simple example without parameters:

$report = new Report('My report name');
$unit = new Unit('Encryption speed');
$unit->addClosure(function ($n) {
    while ($n--) {
        $x = str_rot13('secret');
    }
}, 'rot13');
$unit->addClosure(function ($n) {
    while ($n--) {
        $x = str_rot13(str_rot13('secret'));
    }
}, 'rot26');
$report->unitList->add($unit);
$report->run();

This will generate and save a HTML report to folder build by default.

Options

The Report constructor takes an optional third argument $config:

public function __construct($title, $description = '', $config = array())

If omitted, default options will be used. Otherwise your configuration will be merged with the defaults.

array(
    'template_dir' => 'template',
    'output_dir'   => 'build',
    'twig'         => array(
        'cache'            => 'cache/twig',
        'auto_reload'      => true,
        'strict_variables' => true,
    ),
)

You can also change the minimum duration of tests which defaults to 1000 millseconds (1 second):

\nochso\Benchmark\Timer::$defaultMinDuration = 1000;

Contributing

  1. Open an issue if it's worth discussing.
  2. Fork this project on Github.
  3. Clone your fork: git clone git@github.com:yourname/benchmark.git
  4. Don't forget to composer update
  5. Create your feature branch: git checkout -b my-new-feature
  6. Commit your changes: git commit -am 'Add some feature'
  7. Push to the branch: git push origin my-new-feature
  8. Submit a pull request on Github :)

Change log

See CHANGELOG.

Credits

License

This project is licensed under the ISC license which is MIT/GPL compatible and FSF/OSI approved:

Copyright (c) 2015, Marcel Voigt <mv@noch.so>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.