jbzoo/profiler

This package is abandoned and no longer maintained. The author suggests using the https://github.com/phpbench/phpbench package instead.

Simple Profiler for PHP code and unit tests

1.0.5 2016-04-04 12:20 UTC

This package is auto-updated.

Last update: 2020-06-08 22:38:17 UTC


README

Simple Profiler for PHP code and unit tests

License Latest Stable Version Scrutinizer Code Quality

Usage

use JBZoo\Profiler\Benchmark;

// Compare performance of functions
Benchmark::compare([
    'md5'   => function () {
        $string = str_repeat(mt_rand(0, 9), 1024 * 1024);
        return md5($string);
    },
    'sha1'  => function () {
        $string = str_repeat(mt_rand(0, 9), 1024 * 1024);
        return sha1($string);
    },
    'crc32' => function () {
        $string = str_repeat(mt_rand(0, 9), 1024 * 1024);
        return crc32($string);
    },
], array('count' => 500, 'name' => 'Hash functions'));

/* Result:

  ---------- Start benchmark: Hash functions  ----------
  Running tests 500 times
  PHP Overhead: time=58 ms; memory=0 B;

  Testing 1/3 : md5 ... Done!
  Testing 2/3 : sha1 ... Done!
  Testing 3/3 : crc32 ... Done!

  Name of test    Time, ms    Time, %     Memory    Memory, %
  crc32              1 551          ~    1.25 MB            ~
  md5                1 938         25    1.25 MB            ~
  sha1               2 776         79    1.25 MB            ~

  TOTAL TIME: 6 547.37 ms/4.36 ms;   MEMO: 41.05 KB/0.03 KB;   COUNT: 1 500
  ---------- Finish benchmark: Hash functions  ----------
*/

Benchmark::run(function () {
      $string = str_repeat(mt_rand(0, 9), 1024 * 1024);
      return md5($string);
  }, ['count' => 1000]),

Unit tests and check code style

make
make test-all

License

MIT