PHP code example of nice / bench

1. Go to this page and download the library: Download nice/bench 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/ */

    

nice / bench example snippets




ice\Benchmark\Benchmark;

$benchmark = new Benchmark(100000, 'String matching');
$benchmark->register('preg_match', function() {
        assert(preg_match('/^test/', 'testing'));
    });

$benchmark->register('strpos', function() {
        assert(strpos('testing', 'test') === 0);
    });

$benchmark->execute();



ice\Benchmark\Benchmark;

$arr = range(1, 10000);

$benchmark = new Benchmark(10000, 'foreach');
$benchmark->register('foreach with value', function() use ($arr) {
        foreach ($arr as $value) {
        
        }
    });

$benchmark->register('foreach with key, value', function() use ($arr) {
        foreach ($arr as $key => $value) {
            
        }
    });

$benchmark->execute();
bash
php composer.phar