PHPench creates a graphical output for a PHP benchmark

Overview

PHPench

A pretty graph

PHPench creates a graphical output for a PHP benchmark. Plot the runtime of any function in realtime with GnuPlot and create an image out of the result.

Build Status

Why is it useful?

Algorithms are beautiful

Sometimes the difference between two algorithms is hard to explain but easy to show.
For instance, take two sorting algorithms which both have a best-case runtime of O(n*log n). Depending on the input, one can be much faster than the other. This tools helps you see what's going on.

Death to premature-optimizations

Whenever people tell you that using single quotes instead of double quotes around strings is a performance improvement, it's time to debunk some myths. Most of the time such programmer folklore turns out to be misguided and can actually be pretty harmful.
"Premature emphasis on efficiency is a big mistake which may well be the source of most programming complexity and grief." (Donald Knuth)
Let's be professionals. Let's measure.

Example

Using PHPench feels a bit like writing a visual unit test. Check it out:



require_once __DIR__.'/../vendor/autoload.php';

/*
 * You can use an closure or a class that implements TestInterface.
 *
 * Data that will be processed by the tested function can be executed
 * without including its execution time. This will provide more accurate data.
 */

abstract class AbstractBenchmark implements \mre\PHPench\BenchmarkInterface
{
    protected $test;

    function setUp($arrSize)
    {
        $this->test = array();
        for ($i=1; $i<$arrSize; $i++) {
            $this->test[$i]= $arrSize % $i;
        }

        return $this->test;
    }
}

class BenchmarkArrayFlip extends AbstractBenchmark
{
    public function execute() {
        $test = array_flip(array_flip($this->test));
    }
}

class BenchmarkArrayUnique extends AbstractBenchmark
{
    public function execute() {
        $test = array_unique($this->test);
    }
}

// Create a new benchmark instance
$phpench = new \mre\PHPench(new \mre\PHPench\Aggregator\MedianAggregator);

// Use GnuPlot for output
$oOutput = new \mre\PHPench\Output\GnuPlotOutput('test2.png', 1024, 768);

// Alternatively, print the values to the terminal
//$oOutput = new \mre\PHPench\Output\CliOutput();

$oOutput->setTitle('Compare array_flip and array_unique');
$phpench->setOutput($oOutput);

// Add your test to the instance
$phpench->addBenchmark(new BenchmarkArrayFlip, 'array_flip');
$phpench->addBenchmark(new BenchmarkArrayUnique, 'array_unique');

// Run the benchmark and plot the results in realtime.
// With the second parameter you can specify
// the start, end and step for each call
$phpench->setInput(range(1,pow(2,16), 1024));
$phpench->setRepetitions(4);
$phpench->run();

Installation

1.) Add this package to your composer.json

{
    "require": {
      "mre/phpench": "*@dev"
    }
}

2.) Install gnuplot (Version 4.6)

For Mac OS X you can install gnuplot via homebrew. For live generated charts you also need to install XQuartz.

Without X11 support:
$ brew install homebrew/versions/gnuplot4

With X11 supprt (recommended!):
$ brew install homebrew/versions/gnuplot4 --with-x11

For Linux use your package manager.

apt-get install gnuplot

3.) Look at the examples for usage

Maintainers

Matthias Endler (@matthiasendler)
Markus Poerschke (@markuspoerschke)

License

Apache License Version 2.0

Comments
  • Support for repeated runs

    Support for repeated runs

    Currently we run a benchmark only once for each step. We should repeat the benchmark several times in order to get more accurate results.

    There are many ways to calculate the benchmark result for repeated runs:

    • Take the average time of all runs
    • Report the median time of all runs
    • Report best of n (e.g. best-of-three)
    • ...

    Currently I think about median time as it is a simple way to get rid of outliers.

    enhancement 
    opened by mre 8
  • Composer install not possible

    Composer install not possible

    My composer.json:

    {
        "name": "root/php-benchmarks",
        "authors": [
            {
                "name": "Markus Poerschke",
                "email": "[email protected]"
            }
        ],
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/mre/PHPench.git"
            }
        ],
        "require": {
          "mre/phpench": "*@dev"
        }
    }
    

    Error message:

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Installation request for mre/phpench *@dev -> satisfiable by mre/phpench[dev-master].
        - mre/phpench dev-master requires gregwar/gnuplot @dev -> no matching package found.
    
    Potential causes:
     - A typo in the package name
     - The package is not available in a stable-enough version according to your minimum-stability setting
       see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
    
    Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
    

    Issue: the correct version number for gregwar/gnuplot should be "*@dev". The asterix is missing.

    opened by markuspoerschke 1
  • Add system information to output

    Add system information to output

    Benchmarks are only sound if system information of the test platform is given. This could be added to every output (e.g. as a simple string at the bottom of every diagram). For a start, I propse the following output:

    Operating system, CPU, Memory, PHP Version.
    

    This string is optional and can be modified or removed with simple commands, e.g.

    $phpench->setMachineInfo('');
    
    enhancement 
    opened by mre 0
  • Create bar diagram

    Create bar diagram

    Having a bar diagram would be really nice: Bar diagram

    This could be quite useful for blogposts and articles. It can be done with GnuPlot. For instance, here's the description on how to create the diagram above: http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html

    enhancement 
    opened by mre 0
  • Create more examples

    Create more examples

    Recently I've stumbled over a lot of "best practices" blog posts like this: http://www.mdproductions.ca/guides/50-best-practices-to-optimize-php-code-performance I wonder how much of that is actually true. It would be fun to test a couple of these assumptions with PHPench.

    Also, there's a lot fo benchmarks on http://www.phpbench.com/ that could need some graphs.

    enhancement help wanted 
    opened by mre 0
Owner
Matthias
Curious person. Maker. Rustacean. Oxidizing things.
Matthias
Creates a WorldBorder for PocketMine-MP servers!

This plugin is not yet ready for Poggit or download It is going through mass changes over the next few days Message my Discord to recieve an older eli

Soulz 9 Sep 5, 2021
Analyzes PHPStan baseline files and creates aggregated error trend-reports

Analyzes phpstan baseline files Analyzes PHPStan baseline files and creates aggregated error trend-reports.

Markus Staab 22 Dec 23, 2022
A plugin that creates a level system linked to chatting for PocketMine-MP!

ChatLevel A plugin that creates a level system linked to chatting for PocketMine-MP! Issues You can report bugs by simply clicking me! Support You can

Oğuzhan 2 Oct 28, 2021
Creates Packagist.org mirror site.

Packagist Mirror Creates your own packagist.org mirror site. Requirements PHP ^7.1.3 Installation Clone the repository Install dependencies: php compo

Indra Gunawan 32 Mar 30, 2020
Laravel-hours-helper - Creates a Collection of times with a given interval.

Laravel Hours Helper With laravel-hours-helper you can create a collection of dates and/of times with a specific interval (in minutes) for a specific

Label84 220 Dec 29, 2022
Webman quickly creates a verification code tool similar to Google verification code

webman-captcha-grid webman quickly creates a verification code tool similar to Google verification code webman 快速创建一个类似于 Google 点图验证码的本地验证码扩展 介绍 webma

听风吹雨 6 Dec 5, 2022
PHP Parallel Lint - This tool check syntax of PHP files faster than serial check with fancier output

PHP Parallel Lint This application checks syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Ad

PHP Parallel lint 156 Apr 24, 2022
This tool check syntax of PHP files faster than serial check with fancier output.

PHP Parallel Lint This application checks syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Ad

PHP Parallel lint 202 Dec 22, 2022
Methods to allow the mapping of cases to snake / camel for input / output

Methods to allow the mapping of cases to snake / camel for input / output This is where your description should go. Limit it to a paragraph or two. Co

Craig Smith 4 Aug 31, 2022
🖤Run Laravel artisan tinker from a Vim buffer with output in Ray

Tinkeray Heavily inspired by the absolutely awesome Tinkerwell, run Laravel artisan tinker from a Vim buffer with output in Ray ?? Installation Usage

Jesse Leite 22 Jan 2, 2023
The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3

2021 Nightly Builds Repository PHP-Nuke Evolution Xtreme Developers TheGhost - Ernest Allen Buffington (Lead Developer) SeaBeast08 - Sebastian Scott B

Ernest Buffington 7 Aug 28, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 272 Dec 22, 2022
PHP Meminfo is a PHP extension that gives you insights on the PHP memory content

MEMINFO PHP Meminfo is a PHP extension that gives you insights on the PHP memory content. Its main goal is to help you understand memory leaks: by loo

Benoit Jacquemont 994 Dec 29, 2022
A sampling profiler for PHP written in PHP, which reads information about running PHP VM from outside of the process.

Reli Reli is a sampling profiler (or a VM state inspector) written in PHP. It can read information about running PHP script from outside of the proces

null 258 Sep 15, 2022
A multithreaded application server for PHP, written in PHP.

appserver.io, a PHP application server This is the main repository for the appserver.io project. What is appserver.io appserver.io is a multithreaded

appserver.io 951 Dec 25, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
A PHP 5.3+ and PHP 7.3 framework for OpenGraph Protocol

Opengraph Test with Atoum cd Opengraph/ curl -s https://getcomposer.org/installer | php php composer.phar install --dev ./vendor/atoum/atoum/bin/atoum

Axel Etcheverry 89 Dec 27, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
🐘 A probe program for PHP environment (一款精美的 PHP 探針, 又名X探針、劉海探針)

Simplified Chinese | 简体中文 Traditional Chinese(Taiwan) | 正體中文(臺灣) Traditional Chinese(Hong Kong) | 正體中文(香港) Japanese | 日本語 ?? X Prober This is a probe

Km.Van 1.2k Dec 28, 2022