xp-forge / measure
Measuring performance of different implementations in an xUnit-style way
v3.0.1
2022-02-27 09:33 UTC
Requires
- php: >=7.0.0
- xp-forge/sequence: ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.0 | ^5.0
- xp-framework/core: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
Requires (Dev)
- xp-framework/unittest: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0
README
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