项目作者: hoaproject

项目描述 :
The Hoa\Bench library.
高级语言: PHP
项目地址: git://github.com/hoaproject/Bench.git
创建时间: 2012-08-24T10:30:54Z
项目社区:https://github.com/hoaproject/Bench

开源协议:

下载



Hoa



Build status
Code coverage
Packagist
License



Hoa is a modular, extensible and
structured set of PHP libraries.

Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\Bench

Help on IRC
Help on Gitter
Documentation
Board

This library allows to analyze performance of algorithms or programs by placing
some “marks” in the code. Furthermore, this library provides some
DTrace programs.

Learn more.

Installation

With Composer, to include this library into
your dependencies, you need to
require hoa/bench:

  1. $ composer require hoa/bench '~3.0'

For more installation procedures, please read the Source
page
.

Testing

Before running the test suites, the development dependencies must be installed:

  1. $ composer install

Then, to run all the test suites:

  1. $ vendor/bin/hoa test:run

For more information, please read the contributor
guide
.

Quick usage

We propose a quick overview of two usages: The library itself and one DTrace
program.

Benchmark

All we have to do is to place different marks in the code. A mark can be
started, paused, stopped and reset. The class Hoa\Bench\Bench proposes a quick
statistic graph that could be helpful:

  1. $bench = new Hoa\Bench\Bench();
  2. // Start two marks: “one” and “two”.
  3. $bench->one->start();
  4. $bench->two->start();
  5. usleep(50000);
  6. // Stop the mark “two” and start the mark “three”.
  7. $bench->two->stop();
  8. $bench->three->start();
  9. usleep(25000);
  10. // Stop all marks.
  11. $bench->three->stop();
  12. $bench->one->stop();
  13. // Print statistics.
  14. echo $bench;
  15. /**
  16. * Will output:
  17. * __global__ |||||||||||||||||||||||||||||||||||||||||||||||||||| 77ms, 100.0%
  18. * one |||||||||||||||||||||||||||||||||||||||||||||||||||| 77ms, 99.8%
  19. * two |||||||||||||||||||||||||||||||||| 51ms, 65.9%
  20. * three |||||||||||||||||| 26ms, 33.9%
  21. */

More operations are available, such as iterating over all marks, deleting a
mark, filters marks etc.

DTrace

An interesting DTrace program is hoa://Library/Bench/Dtrace/Execution.d that
shows the call trace, errors and exceptions during an execution. For example, if
we consider the Dtrace.php file that contains the following code:

  1. <?php
  2. function f() { g(); h(); }
  3. function g() { h(); }
  4. function h() { }
  5. f();

Then, we can run DTrace like this:

  1. $ exed=`hoa protocol:resolve hoa://Library/Bench/Dtrace/Execution.d`
  2. $ sudo $exed -c "php Dtrace.php"
  3. Request start
  4. 2ms f() …/Dtrace.php:007
  5. 37ms g() …/Dtrace.php:003
  6. 26ms h() …/Dtrace.php:004
  7. 28ms h()
  8. 37ms g()
  9. 44ms h() …/Dtrace.php:003
  10. 25ms h()
  11. 30ms f()
  12. Request end

Another program shows statistics about an execution: Each function that has been
called, how many times, how long the execution has taken etc.

Documentation

The
hack book of Hoa\Bench
contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

  1. $ composer require --dev hoa/devtools
  2. $ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project’s website:
hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor
guide
explains
everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see
LICENSE for details.

The following projects are using this library: