Git Product home page Git Product logo

php-benchmark's Introduction

PHP Benchmark

Tool to compare different functions in PHP

Install

Via Composer

composer require lavoiesl/php-benchmark

Usage

<?php
$benchmark = new \Lavoiesl\PhpBenchmark\Benchmark();

$benchmark->add('md5',   function() { return md5('test');   });
$benchmark->add('sha1',  function() { return sha1('test');  });

$benchmark->run();
?>

You can run $benchmark->run(false) to get results without any output

Notes about memory usage

Memory usage is monitored using register_tick_function but this does not do a good job at analysing small statements since the memory gets cleaned too quickly.

A simple trick is the return the value, the AbstractTest stores it temporarily.

To ensure proper tick analysis, use declare(ticks = 1); as early as possible.

See the memory test.

Output

Running tests 3000 times.
Testing 2/2 : sha1

Test       Time   Time (%)   Memory   Memory (%)
md5     1304 ms                 0 B
sha1    2077 ms       59 %      0 B

Optimal test count guessing

By default, Benchmark will try to find an optimal number of runs so that each test takes a maximum of 2 seconds.

You can change this by forcing it with $benchmark->setCount($n) or change the time with $benchmark->guessCount($max_seconds).

Writing custom tests

You can extend AbstractTest and provide your own wrapper.

For an example of this, see the command test and the corresponding class.

A full example can be seen here: https://github.com/lavoiesl/php-cache-comparison

php-benchmark's People

Contributors

joel-depiltech avatar lavoiesl avatar michaelkaefer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-benchmark's Issues

Memory usage?

I feel like the memory usage is not completely correct. Sometimes it's 0 for a test, and a few bytes for another.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.