Skip to content

cigraphics/PHP-Benchmark

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-Benchmark

This library contains classes used to compare algorithms and benchmark your application.

Benchmarking

Setup

  1. Either download the library to your server or install it in your project using composer
  2. Include the file init.php in the very beginning of the first file that receives the request to your application (this is usually index.php). Then load the address of your website in the browser with the query parameters php-benchmark-test=1&display-data=1 and the benchmark data will be displayed in the upper left corner of your website.

Becnhmark 1

Taking snapshots

If you want to take snapshots from the benchmark data during the request you may do so by adding the following code.

 \PHPBenchmark\Monitor::instance()->snapshot('Bootstrap finished');

Inserting some snapshots in the source code of WordPress gave me the following benchmark data

Becnhmark 1

Comparing algorithms

Setup (composer)

Add the dependency "phpbenchmark/phpbenchmark" to composer.json and your'e set to go.

Example code

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

use \PHPBenchmark\testing\FunctionComparison;

FunctionComparison::load()
    ->addFunction('stream_resolve_include_path', function() {
        $bool = stream_resolve_include_path(__FILE__) !== false;
    })
    ->addFunction('file_exists', function() {
        $bool = file_exists(__FILE__);
    })
    ->exec();

Load a file having this code in the browser, or call it via command line, and you will find out which function that wins the game.

You can also call ->run() to get hold of an object representing the results of the comparison test. Read more in the docs.

About

Easy to use benchmark script for your PHP-application. Get information about average loading time, memory consumption and more...

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 75.3%
  • JavaScript 24.7%