Skip to content

Commit e24960d

Browse files
committed
Add benchmarks.
1 parent afa6445 commit e24960d

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

benchmarks/AbstractBench.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace drupol\phptree\benchmarks;
6+
7+
abstract class AbstractBench
8+
{
9+
/**
10+
* @return array
11+
*/
12+
public function getData()
13+
{
14+
return \range(1, 100);
15+
}
16+
}

benchmarks/DrupolPhpTreeBench.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace drupol\phptree\benchmarks;
6+
7+
use drupol\phptree\Node\ValueNode;
8+
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
9+
10+
/**
11+
* @Groups({"drupol/phptree"})
12+
* @BeforeMethods({"initObject"})
13+
*/
14+
class DrupolPhpTreeBench extends AbstractBench
15+
{
16+
/**
17+
* @var \drupol\phptree\Node\NodeInterface
18+
*/
19+
private $tree;
20+
21+
/**
22+
* Init the object.
23+
*/
24+
public function initObject()
25+
{
26+
}
27+
28+
/**
29+
* @Revs({1, 100, 1000})
30+
* @Iterations(5)
31+
* @Warmup(10)
32+
*/
33+
public function benchHash()
34+
{
35+
$this->tree = new ValueNode();
36+
37+
foreach ($this->getData() as $value) {
38+
$this->tree->add(new ValueNode($value));
39+
}
40+
}
41+
}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
},
4646
"autoload-dev": {
4747
"psr-4": {
48-
"drupol\\phptree\\tests\\": "tests/src/"
48+
"drupol\\phptree\\tests\\": "tests/src/",
49+
"drupol\\phptree\\benchmarks\\": "benchmarks/"
4950
}
5051
},
5152
"config": {

0 commit comments

Comments
 (0)