Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wdalmut/php-bench
benchmark your PHP application methods in a simple way
https://github.com/wdalmut/php-bench
Last synced: 1 day ago
JSON representation
benchmark your PHP application methods in a simple way
- Host: GitHub
- URL: https://github.com/wdalmut/php-bench
- Owner: wdalmut
- Created: 2015-10-21T13:06:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-24T10:31:16.000Z (almost 9 years ago)
- Last Synced: 2024-05-02T00:45:15.561Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 218 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Benchmark your class methods or functions
[![Build Status](https://travis-ci.org/wdalmut/php-bench.svg?branch=master)](https://travis-ci.org/wdalmut/php-bench)
Just a simple way to benchmark your class methods or functions.
```sh
./vendor/bin/bench run tests/
```or with different paths
```sh
./vendor/bin/bench run tests/ benchs/
```## Declare a bench method
Just create a method in a class starting with the `benchmark` keyword or use a
simple `@benchmark` annotation in your doc-block.```php
class MyClass
{
...public function benchmarkUsingTheMethodName($b)
{
for ($i=0; $i<$b->times(); $i++) {
my_project_function("%s", "hello");
}
}/**
* @benchmark
*/
public function this_bench_instead_use_the_annotation($b) {
for ($i=0; $i<$b->times(); $i++) {
$myObj->slowMethod("stub");
}
}
}
```The `benchmark` method receive an object `b` from outside that contains the
number of iterations that your bench function should run.## PHPUnit integration
Just add a `benchmark` method in your testcases.
```php
class MyTest extends \PHPUnit_Framework_TestCase
{
// Executed only by php-bench
public function benchmarkMyAppMethod($b)
{
for ($i<0; $i<$b->times(); $i++) {
sprintf("%s", "hello");
}
}public function testMyAppMethod()
{
// ...
$this->assertEquals(...);
}
}
```## Install with composer
You can use composer in order to get this library locally
```json
{
"require-dev": {
"wdalmut/php-bench": "*"
}
}
```Inspired by Golang benchmark library