PHPackages                             hoa/bench - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. hoa/bench

AbandonedArchivedLibrary[Debugging &amp; Profiling](/categories/debugging)

hoa/bench
=========

The Hoa\\Bench library.

3.17.01.11(9y ago)57355.3k↓11.1%6[2 PRs](https://github.com/hoaproject/Bench/pulls)BSD-3-ClausePHP

Since Sep 16Pushed 7y ago10 watchersCompare

[ Source](https://github.com/hoaproject/Bench)[ Packagist](https://packagist.org/packages/hoa/bench)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-bench/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (0)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/d482a5f01ba89e3317f7f2d6dd32534e7aaccfa695eea55d3192c46aa8410a7c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f62656e63682f6d61737465722e737667)](https://travis-ci.org/hoaproject/bench) [![Code coverage](https://camo.githubusercontent.com/ebf703b1e0de319fda965207d69a2ef0d2871000d17dbc818de936aa9f758648/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f62656e63682f6d61737465722e737667)](https://coveralls.io/github/hoaproject/bench?branch=master) [![Packagist](https://camo.githubusercontent.com/b62dbed1258051e31400947b769265878539f20fdaacef3825ad04646aa20695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f62656e63682e737667)](https://packagist.org/packages/hoa/bench) [![License](https://camo.githubusercontent.com/84963d687d722fcb05ea042ee344429c3200383d243ace79aadb83b13e36ca18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f62656e63682e737667)](https://hoa-project.net/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
==========

[](#hoabench)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Bench)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/bench)

This library allows to analyze performance of algorithms or programs by placing some “marks” in the code. Furthermore, this library provides some [DTrace](http://dtrace.org/guide/) programs.

[Learn more](https://central.hoa-project.net/Documentation/Library/Bench).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/bench`](https://packagist.org/packages/hoa/bench):

```
$ composer require hoa/bench '~3.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

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

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

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

### Benchmark

[](#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:

```
$bench = new Hoa\Bench\Bench();

// Start two marks: “one” and “two”.
$bench->one->start();
$bench->two->start();

usleep(50000);

// Stop the mark “two” and start the mark “three”.
$bench->two->stop();
$bench->three->start();

usleep(25000);

// Stop all marks.
$bench->three->stop();
$bench->one->stop();

// Print statistics.
echo $bench;

/**
 * Will output:
 *     __global__  ||||||||||||||||||||||||||||||||||||||||||||||||||||    77ms, 100.0%
 *     one         ||||||||||||||||||||||||||||||||||||||||||||||||||||    77ms,  99.8%
 *     two         ||||||||||||||||||||||||||||||||||                      51ms,  65.9%
 *     three       ||||||||||||||||||                                      26ms,  33.9%
 */
```

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

### DTrace

[](#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:

```
