Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

JBZoo/Profiler

Repository files navigation

JBZoo Profiler Build Status Coverage Status

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