Skip to content

Instantly share code, notes, and snippets.

@dantleech
Last active January 16, 2017 20:04
Show Gist options
  • Select an option

  • Save dantleech/b442a77dc75c325c83d89b1c2c7db3cb to your computer and use it in GitHub Desktop.

Select an option

Save dantleech/b442a77dc75c325c83d89b1c2c7db3cb to your computer and use it in GitHub Desktop.
~/w/p/phpbench ❯❯❯ ./bin/phpbench run benchmarks/Micro/HashLookupBench.php --revs=1000 --report=aggregate --iterations=40 --report='extends: aggregate, cols: [ "params", "revs", "its", "mem_peak", "mean", "mode", "rstdev", "diff"]'
PhpBench 0.14-dev (@git_version@). Running benchmarks.
Using configuration file: /home/daniel/www/phpbench/phpbench/phpbench.json.dist
\PhpBench\Benchmarks\Micro\HashBench
benchLookup I39 P0 [μ Mo]/r: 8.864 8.516 (μs) [μSD μRSD]/r: 1.383μs 15.60%
benchLookup I39 P1 [μ Mo]/r: 9.124 8.661 (μs) [μSD μRSD]/r: 1.340μs 14.69%
benchLookup I39 P2 [μ Mo]/r: 9.090 8.769 (μs) [μSD μRSD]/r: 1.418μs 15.60%
1 subjects, 120 iterations, 3,000 revs, 0 rejects
(best [mean mode] worst) = 8.013 [9.026 8.649] 16.384 (μs)
⅀T: 1,083.113μs μSD/r 1.380μs μRSD/r: 15.295%
suite: 133c584d9f23a442098177ff8b614276a95f41b4, date: 2017-01-16, stime: 20:01:11
+-------------------+------+-----+------------+---------+---------+--------+--------+
| params | revs | its | mem_peak | mean | mode | rstdev | diff |
+-------------------+------+-----+------------+---------+---------+--------+--------+
| {"algo":"_none_"} | 1000 | 40 | 1,034,968b | 8.864μs | 8.516μs | 15.60% | 0.00% |
| {"algo":"md5"} | 1000 | 40 | 931,088b | 9.124μs | 8.661μs | 14.69% | +2.93% |
| {"algo":"sha1"} | 1000 | 40 | 931,088b | 9.090μs | 8.769μs | 15.60% | +2.55% |
+-------------------+------+-----+------------+---------+---------+--------+--------+
<?php
namespace PhpBench\Benchmarks\Micro;
class HashBench
{
private $hashes = [];
private $hashKeys = [];
public function generateHashes($params)
{
$ret = [];
$size = 1000;
$nbHashes = 100;
for ($i = 0; $i < $nbHashes; $i++) {
$data = '';
for ($ii = 0; $ii < $size; $ii++) {
$data .= chr(rand(47, 127));
}
if ('_none_' === $params['algo']) {
$this->hashes[$data] = 'hello';
continue;
}
$this->hashes[hash($params['algo'], $data)] = 'hello';
}
$this->hashKeys = array_keys($this->hashes);
}
/**
* @ParamProviders({"provideAlgos"})
* @BeforeMethods({"generateHashes"})
*/
public function benchLookup($params)
{
foreach ($this->hashKeys as $key) {
$this->hashes[$key];
}
}
public function provideAlgos()
{
return [
[
'algo' => '_none_',
],
[
'algo' => 'md5',
],
[
'algo' => 'sha1'
],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment