PHP code example of dragon-code / benchmark

1. Go to this page and download the library: Download dragon-code/benchmark library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dragon-code / benchmark example snippets


use DragonCode\Benchmark\Benchmark;

Benchmark::start()->compare(
    fn () => /* some code */,
    fn () => /* some code */,
);

Benchmark::start()->compare([
    fn () => /* some code */,
    fn () => /* some code */,
]);

Benchmark::start()->compare([
    'foo' => fn () => /* some code */,
    'bar' => fn () => /* some code */,
]);

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->iterations(5)
    ->compare(
        fn () => /* some code */,
        fn () => /* some code */,
    );

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->iterations(5)
    ->compare(
        fn (int $iteration) => /* some code */,
        fn (int $iteration) => /* some code */,
    );

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->withoutData()
    ->compare([
        'foo' => fn () => /* some code */,
        'bar' => fn () => /* some code */,
    ]);

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->iterations(5)
    ->round(2)
    ->compare(
        fn () => /* some code */,
        fn () => /* some code */,
    );

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->prepare(fn () => /* some code */)
    ->compare(
        fn () => /* some code */,
        fn () => /* some code */,
    );

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->prepare(fn (mixed $name, int $iteration) => /* some code */)
    ->compare(
        fn () => /* some code */,
        fn () => /* some code */,
    );

use DragonCode\Benchmark\Benchmark;

Benchmark::start()
    ->prepare(fn (mixed $name, int $iteration) => /* some code */)
    ->compare(
        fn (int $iteration, mixed $prepareResult) => /* some code */,
        fn (int $iteration, mixed $prepareResult) => /* some code */,
    );