-
Notifications
You must be signed in to change notification settings - Fork 0
Home
jarretth edited this page Oct 24, 2012
·
7 revisions
Things I want, in order
- Time-based benchmarking - duh
- Nesting
- Manual and closure
- Output of benchmark results in plaintext to stdout
- Global configuration
- off/on, output location, output format, metric
-
getrusage()
-based metrics? - Output to files
- Basic statistics(Mean/Mode and such)
- Different output formats(HTML,JSON)
- Ability to POST output
- Configure statistics to output
- Better statistics, plots, images, etc
Sample uses(in the future):
<?php
$config = array('enabled' => true, 'output' => 'stdout', 'format' => 'plain', 'verbose' => true);
Benchmark::configure($config);
//Benchmark a function
Benchmark::bench('Foreach', function() { foreach(array(1,2,3) as $i) { $s = "${i}"; } });
//Benchmark a function 100 times
Benchmark::bench('Foreach', function() { foreach(array(1,2,3) as $i) { $s = "${i}"; } }, 100);
//Benchmark a function 100 times manually
for($i = 0; $i < 100; $i++) {
Benchmark::start('Array Map');
array_walk(array(1,2,3),function($i) { $s = "${i}"; });
Benchmark::stop();
}
echo "For example: ".Benchmark::time('Foreach')."\n";
echo "Or maybe: ".Benchmark::avg('Foreach')."\n";
Benchmark::done();
Sample output(to start):
For example: 0.000001
Or maybe: 0.000001
Foreach:
1. 0.000001
2. 0.000002
3. 0.000001
...
101. 0.000002
Average: 0.000001
Array map:
1. 0.000001
...
100. 0.000003
Average: 0.000002
I dunno, something like that. It should always be simple enough to use in phpsh.
When disabled, Benchmark::stop()
, Benchmark::stop()
, Benchmark::done()
, etc will do nothing. Benchmark::time()
will return 0. Benchmark::bench()
will execute its callback once with no timing - ideally this can be left in scripts and turned on for testing and turned off for real usage