2017 © Pedro Peláez
 

library benchmarker

Benchmark running times of PHP code

image

moznion/benchmarker

Benchmark running times of PHP code

  • Wednesday, October 1, 2014
  • by moznion
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

BenchMarker Build Status

Benchmark running times of PHP code (inspired by Benchmark.pm), (*1)

Synopsis

$benchmarker = new \Moznion\Benchmarker("all");

$code = function () use ($foo) {
    // do something
};

$benchmarker->timeThese(10000, [
    "code A" => function () use ($bar) {
        // do something
    },
    "code B" => $code, // it can also take variable of anonymous function
]);
// Sample of Output:
//    code A: 3.9326 wallclock secs (3sr + 0.2562ys = PU)
//    code B: 6.40877 wallclock secs (6sr + 0.81337ys = PU)

$benchmarker->cmpThese(10000, [
    "code A" => function () use ($bar) {
        // do something
    },
    "code B" => $code, // it can also take variable of anonymous function
]);
// Sample of Output:
//               Rate  code A  code B
//    code A  22571/s      --    -49%
//    code B  44656/s     98%      --

Description

Library for benchmarking the running times of PHP code., (*2)

This library is inspired by Benchmark of Perl, (*3)

Methods

new($style_name=null, $format=null, $enable_cache=null)

Creates the instance of BenchMarker., (*4)

  • $style_name (String)

Specify the name of style. Default value is auto., (*5)

Please see also Style., (*6)

  • $format (String)

Specify the format to format the values of benchmark's result. It supports the format which is compatible with sprintf()'s one., (*7)

Default value is '5.2f'., (*8)

  • $enable_cache (Boolean)

Specify cache the elapsed time of nop function (elapsed time of nop is used internal for accuracy). If you enable caching, processing time of benchmark will be faster., (*9)

Default value is 'false'., (*10)

timeIt($count, $code)

Run a chunk of code and see how long it goes., (*11)

This method returns instance of result-time., (*12)

  • $count

$count is the number of times to run the loop. This argument must be positive integer., (*13)

  • $code

$code is the code to run. This argument must be callable variable., (*14)

countIt($time, $code)

See how many times a chunk of code runs in a given time., (*15)

This method returns instance of result-time., (*16)

  • $time

$time is the minimum length of time to run the loop., (*17)

  • $code

$code is the code to run. This argument must be callable variable., (*18)

timeThis($count, $code, $title=null)

Run a chunk of code several times and print result of benchmark., (*19)

This method returns instance of result-time., (*20)

  • $count

$count is the number of times to run the loop. This argument must be positive integer., (*21)

This argument can be zero or negative. This means the minimum number of CPU seconds to run. A zero signifies the default of 3 seconds., (*22)

  • $code

$code is the code to run. This argument must be callable variable., (*23)

  • $title

Title of result. $title defaults to "timethis $count"., (*24)

timeThese($count, $codes)

Run several chunks of code several times and print result of benchmark., (*25)

This method returns instance of result-time of array for each codes., (*26)

  • $count

$count is the number of times to run the loop. This argument must be positive integer., (*27)

This argument can be zero or negative. This means the minimum number of CPU seconds to run. A zero signifies the default of 3 seconds., (*28)

  • $codes

$codes is the array of codes to run., (*29)

cmpThese($count, $codes)

Print results of timeThese as a comparison chart., (*30)

  • $count

$count is the number of times to run the loop. This argument must be positive integer., (*31)

This argument can be zero or negative. This means the minimum number of CPU seconds to run. A zero signifies the default of 3 seconds., (*32)

  • $codes

$codes is the array of codes to run., (*33)

timeStr($time_result, $count=null)

Print formatted time., (*34)

  • $time_result

instance of result-time., (*35)

  • $count

Number of loops. If this argument is not null then this method appends the rate., (*36)

timeDiff($new_time, $old_time)

Calculates difference between $new_time and $old_time., (*37)

Arguments must be instance of result-time., (*38)

clearCache($count)

Clear the caching of nop function which is related $count., (*39)

clearAllCache()

Clear all of the caching of nop function., (*40)

disableCache()

Disable to cache the caching of nop function., (*41)

enableCache()

Enable to cache the caching of nop function., (*42)

Result Time

Time class has 6 public members., (*43)

  • $real_time

Real duration., (*44)

  • $sys_time

Duration of system time., (*45)

  • $user_time

Duration of user time., (*46)

  • $child_sys_time

Duration of system time of child processes., (*47)

  • $child_user_time

Duration of user time of child processes., (*48)

  • $count

Times of loop to run., (*49)

Style

This library supports 5 styles., (*50)

  • all

Output all of the result of benchmarking., (*51)

  • noc

Output the result of benchmarking without child processes result., (*52)

  • nop

Output the result of benchmarking without parent processes result., (*53)

  • none

Output nothing., (*54)

  • auto

If child processes CPU time is bigger than 0 then this style is the same as "all". Elsewise, this style is the same as "noc"., (*55)

Requires

PHP (version 5.4 or later), (*56)

See Also

Notes

This library doesn't work on Microsoft Windows., (*57)

License

MIT, (*58)

The Versions

01/10 2014

dev-master

9999999-dev https://github.com/moznion/BenchMarker

Benchmark running times of PHP code

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar moznion

benchmark

29/09 2014

v1.1.0

1.1.0.0 https://github.com/moznion/BenchMarker

Benchmark running times of PHP code

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar moznion

benchmark

26/09 2014

v1.0.0

1.0.0.0 https://github.com/moznion/BenchMarker

Benchmark running times of PHP code

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar moznion

benchmark