https://github.com/smuuf/phpcb
A tiny benchmarking tool for PHP for true lovers of micro-optimization.
https://github.com/smuuf/phpcb
benchmark performance php speed-benchmarking
Last synced: 3 months ago
JSON representation
A tiny benchmarking tool for PHP for true lovers of micro-optimization.
- Host: GitHub
- URL: https://github.com/smuuf/phpcb
- Owner: smuuf
- License: mit
- Created: 2015-09-23T23:39:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-21T15:18:47.000Z (over 3 years ago)
- Last Synced: 2025-03-12T22:18:43.815Z (3 months ago)
- Topics: benchmark, performance, php, speed-benchmarking
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
[](https://github.com/smuuf/phpcb/actions/workflows/php.yml)
# phpcb (php code benchmark)
**phpcb** is a very simple and very lightweight tool for speed benchmarking of various little pieces of PHP code, written in PHP, of course.
### Why
**phpcb** is meant to be used in those situations when there are multiple ways of how to do something - and you *know* all will have the exact same result - but you ***just can't*** decide which would ultimately be the best (meaning "*fastest*") to use.### Requirements
- PHP 7.4+
- *BCMath Arbitrary Precision Mathematics* library for PHP; shouldn't be a problem, since it is commonly shipped with PHP itself.### Installation
```
composer require --dev smuuf/-hpcb
```### Usage
Write your microbenchmarks in a some file. For example `mymicrobench.php` _(here placed in phpcb's root directory, so it's clear we rquire Composer's autoload file from correct place)_:
```php
addBench(function() {
for ($i = 1; $i <= COUNT; $i++) {}
});$bench->addBench(function() {
for ($i = COUNT; $i > 0; $i--) {}
});$bench->addBench(function() {
for ($i = COUNT; $i--;) {}
});$bench->addBench(function() {
for ($i = -COUNT; $i++;) {}
});$bench->run();
```And then run it:
```bash
$ php ./mymicrobench.php
```And observe results:
```php
█ PHP Code Benchmark (phpcb)
█ PHP 7.4.27Engine used: Chaotic Engine
Total time: 1.3220 sec
Iterations: 1 000 000██ 2. Score: 100.00, 0.2660 sec
┌
│ $bench->addBench(function() {
│ for ($i = COUNT; $i > 0; $i--) {}
│ });
└██ 1. Score: 86.54, 0.3074 sec, 1.16x slower
┌
│ $bench->addBench(function() {
│ for ($i = 1; $i <= COUNT; $i++) {}
│ });
└██ 4. Score: 71.13, 0.3740 sec, 1.41x slower
┌
│ $bench->addBench(function() {
│ for ($i = -COUNT; $i++;) {}
│ });
└██ 3. Score: 71.02, 0.3746 sec, 1.41x slower
┌
│ $bench->addBench(function() {
│ for ($i = COUNT; $i--;) {}
│ });
└
```