GithubHelp home page GithubHelp logo

sergix44 / php-benchmark-script Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 4.0 36 KB

A simple PHP script that helps you compare raw performance across servers and php versions

License: GNU General Public License v3.0

PHP 100.00%
bench benchmark performance performance-testing php script benchphp

php-benchmark-script's Introduction

PHP Benchmark Script

A simple script that calculate execution time of common control flows and function of the PHP. Helps you to compare performances of servers, web hosting and also across PHP versions.

Usage

From your SSH:

curl https://raw.githubusercontent.com/SergiX44/php-benchmark-script/master/bench.php | php

Or upload the file bench.php to your web document root and visit it.

Parameters

You can change the difficulty multiplier by passing a multiplier parameter:

php bench.php --multiplier=2

Additional tests

You must have the bench.php file to your server. You can download additional benchmarks (must be in the same directory as bench.php) using:

Available tests:

# rand: random number generation
wget https://raw.githubusercontent.com/SergiX44/php-benchmark-script/master/rand.bench.php
# io: file read/write/zip/unzip
wget https://raw.githubusercontent.com/SergiX44/php-benchmark-script/master/io.bench.php

Then you can run the benchmark using:

php bench.php

If the file is in the same directory as bench.php, it will be automatically loaded.

Custom tests

You can create your own tests by creating a file in the same directory as bench.php and the file must be named *.bench.php.

The file must return a closure, or an array of closures. Each closure should take a parameter $multiplier which is how hard the test should be. The higher the $multiplier, the longer the test will take, by default it is 1. You should choose a reasonable number of iterations for your test (e.g. 1000) and multiply it by the $multiplier.

Example:

// mytest.bench.php

return function ($multiplier = 1) {
    $iterations = 1000 * $multiplier;
    for ($i = 0; $i < $iterations; ++$i) {
        // do something
    }
};

Or with multiple tests:

// mytest.bench.php

return [
    'my_test' => function ($multiplier = 1) {
        $iterations = 1000 * $multiplier;
        for ($i = 0; $i < $iterations; ++$i) {
            // do something
        }
    },
    'another_test' => function ($multiplier = 1) {
        $iterations = 1000 * $multiplier;
        for ($i = 0; $i < $iterations; ++$i) {
            // do something else
        }
    },
];

Example Output

-------------------------------------------------------
|       PHP BENCHMARK SCRIPT v.2.0 by @SergiX44       |
-------------------------------------------------------
PHP............................................. 8.2.10
Platform........................................ Darwin
Arch............................................. arm64
Server........................................ hostname
Max memory usage.................................. 512M
OPCache status................................. enabled
OPCache JIT.................................... enabled
PCRE JIT....................................... enabled
XDebug extension.............................. disabled
Difficulty multiplier............................... 1x
Started at..................... 06/12/2023 13:45:37.453
-------------------------------------------------------
math.......................................... 0.0935 s
loops......................................... 0.0121 s
ifelse........................................ 0.0173 s
switch........................................ 0.0172 s
string........................................ 0.1842 s
array......................................... 0.3212 s
regex......................................... 0.1769 s
is_{type}..................................... 0.0322 s
hash.......................................... 0.1202 s
json.......................................... 0.1586 s
-----------------Additional Benchmarks-----------------
io::file_read................................. 0.0129 s
io::file_write................................ 0.0715 s
io::file_zip.................................. 0.5335 s
io::file_unzip................................ 0.1571 s
rand::rand.................................... 0.0089 s
rand::mt_rand................................. 0.0089 s
rand::random_int.............................. 0.0679 s
rand::random_bytes............................ 0.2320 s
rand::openssl_random_pseudo_bytes............. 0.2953 s
-------------------------------------------------------
Total time.................................... 2.5214 s
Peak memory usage................................ 2 MiB

Authors

License

MIT

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.