xp-forge/measure

Measuring performance of different implementations in an xUnit-style way

v3.0.1 2022-02-27 09:33 UTC

This package is auto-updated.

Last update: 2024-10-27 15:08:59 UTC


README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version

Measuring performance of different implementations in an xUnit-style way.

Example

use util\profiling\{Measure, Measurable};

class Iteration extends Measurable {
  
  #[Measure]
  public function strpos() {
    return false === ($p= strpos('abc.', '.')) ? -1 : $p;
  }

  #[Measure]
  public function strcspn() {
    return 4 === ($p= strcspn('abc.', '.')) ? -1 : $p;
  }
}

Running:

$ xp measure -1000000 Demo
strpos: 1000000 iteration(s), 0.308 seconds, result= 3
strcspn: 1000000 iteration(s), 0.350 seconds, result= 3

Permutation

use util\profiling\{Measure, Measurable, Values};

class Demo extends Measurable {

  #[Measure, Values(['', '.', '.a', 'a.', 'a.b'])]
  public function strpos($fixture) {
    return false === ($p= strpos($fixture, '.')) ? -1 : $p;
  }

  #[Measure, Values(['', '.', '.a', 'a.', 'a.b'])]
  public function strcspn($fixture) {
    return strlen($fixture) === ($p= strcspn($fixture, '.')) ? -1 : $p;
  }
}

Running:

$ xp measure -1000000 Demo
strpos(""): 1000000 iteration(s), 0.534 seconds, result= -1
strpos("."): 1000000 iteration(s), 0.527 seconds, result= 0
strpos(".a"): 1000000 iteration(s), 0.523 seconds, result= 0
strpos("a."): 1000000 iteration(s), 0.531 seconds, result= 1
strpos("a.b"): 1000000 iteration(s), 0.541 seconds, result= 1
strcspn(""): 1000000 iteration(s), 0.633 seconds, result= -1
strcspn("."): 1000000 iteration(s), 0.617 seconds, result= 0
strcspn(".a"): 1000000 iteration(s), 0.622 seconds, result= 0
strcspn("a."): 1000000 iteration(s), 0.605 seconds, result= 1
strcspn("a.b"): 1000000 iteration(s), 0.613 seconds, result= 1