Skip to content

Commit 65cb31a

Browse files
committed
Working
1 parent 37f9ac7 commit 65cb31a

File tree

8 files changed

+176135
-15
lines changed

8 files changed

+176135
-15
lines changed

benchmarks/BaseBench.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace PHPCR\Benchmark;
44

5-
use PhpBench\BenchCase;
65
use PHPCR\NodeInterface;
6+
use PhpBench\Benchmark;
7+
use PHPCR\ImportUUIDBehaviorInterface;
78

8-
abstract class BaseBench
9+
abstract class BaseBench implements Benchmark
910
{
1011
const ROOT_NAME = 'bench';
1112
const ROOT_PATH = '/bench';
@@ -21,10 +22,16 @@ protected function getSession()
2122
}
2223

2324
$this->session = $this->getLoader()->getSession();
25+
$this->getNodeTypeManager()->registerNodeTypesCnd(file_get_contents(__DIR__ . '/../dumps/nodetypes.cnd'), true);
2426

2527
return $this->session;
2628
}
2729

30+
protected function getNodeTypeManager()
31+
{
32+
return $this->getWorkspace()->getNodeTypeManager();
33+
}
34+
2835
protected function resetSession()
2936
{
3037
$this->getSession()->logout();
@@ -34,7 +41,6 @@ protected function resetSession()
3441
protected function resetWorkspace()
3542
{
3643
$rootNode = $this->getSession()->getRootNode();
37-
3844
if ($rootNode->hasNode(self::ROOT_NAME)) {
3945
$this->getSession()->removeItem(self::ROOT_PATH);
4046
}
@@ -55,11 +61,6 @@ protected function getLoader()
5561
return $this->loader;
5662
}
5763

58-
protected function loadFixtures($identifier)
59-
{
60-
$this->getLoader()->getFixtureLoader()->import($identifier);
61-
}
62-
6364
protected function getQueryManager()
6465
{
6566
return $this->getWorkspace()->getQueryManager();
@@ -92,4 +93,27 @@ protected function getRootNode()
9293
{
9394
return $this->rootNode;
9495
}
96+
97+
protected function loadDump($filename, $remove = false)
98+
{
99+
$dumpPath = __DIR__ . '/../dumps/' . $filename;
100+
101+
if (!file_exists($dumpPath)) {
102+
throw new \Exception('Could not find dump file: ' . $dumpPath);
103+
}
104+
105+
$rootNode = $this->getSession()->getRootNode();
106+
107+
if (false === $remove && $rootNode->hasNode($filename)) {
108+
return;
109+
}
110+
111+
if (true === $rootNode->hasNode($filename)) {
112+
$rootNode->remove($filename);
113+
}
114+
115+
$rootNode->addNode($filename, 'nt:unstructured');
116+
$this->getSession()->importXML('/' . $filename, $dumpPath, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
117+
$this->getSession()->save();
118+
}
95119
}

benchmarks/Query/InsertBench.php renamed to benchmarks/InsertBench.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace PHPCR\Benchmark\Query;
3+
namespace PHPCR\Benchmark;
44

5-
use PHPCR\Benchmark\BaseBench;
65
use PhpBench\Benchmark;
76
use PhpBench\Benchmark\Iteration;
7+
use PHPCR\Benchmark\BaseBench;
88

9-
class InsertBench extends BaseBench implements Benchmark
9+
class InsertBench extends BaseBench
1010
{
1111
/**
1212
* @description Insert nodes

benchmarks/Query/QueryBench.php renamed to benchmarks/QueryBench.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace PHPCR\Benchmark\Query;
44

5-
use PHPCR\Benchmark\BaseBench;
6-
use PhpBench\Benchmark;
75
use PhpBench\Benchmark\Iteration;
6+
use PHPCR\Benchmark\BaseBench;
87

9-
class QueryBench extends BaseBench implements Benchmark
8+
class QueryBench extends BaseBench
109
{
1110
/**
1211
* @description Run a select query

benchmarks/QueryBench2.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace PHPCR\Benchmark\Query;
4+
5+
use PhpBench\Benchmark\Iteration;
6+
use PHPCR\Benchmark\BaseBench;
7+
8+
class QueryBench2 extends BaseBench
9+
{
10+
public function setUp()
11+
{
12+
$this->loadDump('large_website.xml');
13+
}
14+
15+
/**
16+
* @description Run a select query. No iterations
17+
* @paramProvider provideQueries
18+
* @iterations 5
19+
*/
20+
public function benchQuery(Iteration $iteration)
21+
{
22+
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
23+
$query->execute();
24+
}
25+
26+
/**
27+
* @description Run a select query. Retrive nodes for each row
28+
* @paramProvider provideQueries
29+
* @iterations 5
30+
*/
31+
public function benchQueryWithNodes(Iteration $iteration)
32+
{
33+
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
34+
$results = $query->execute();
35+
36+
foreach ($results as $result) {
37+
$result->getNode();
38+
}
39+
}
40+
41+
/**
42+
* @description Run a select query. Iterate over rows and retrieve properties
43+
* @paramProvider provideQueries
44+
* @iterations 5
45+
*/
46+
public function benchQueryIterate(Iteration $iteration)
47+
{
48+
$query = $this->getQueryManager()->createQuery($iteration->getParameter('query'), 'JCR-SQL2');
49+
$results = $query->execute();
50+
51+
foreach ($results as $result) {
52+
$result->getNode();
53+
}
54+
}
55+
56+
/**
57+
* @description Run a select query with variable amount of properties
58+
* @paramProvider provideProperties
59+
* @iterations 5
60+
*/
61+
public function benchQueryIterateVariableProperties(Iteration $iteration)
62+
{
63+
$props = $iteration->getParameter('props');
64+
$query = $this->getQueryManager()->createQuery(sprintf(
65+
'SELECT %s FROM [nt:unstructured] WHERE valves IS NOT NULL'
66+
, implode(', ', $props)), 'JCR-SQL2');
67+
68+
$results = $query->execute();
69+
70+
foreach ($results as $row) {
71+
foreach ($props as $prop) {
72+
$row->getValue($prop);
73+
}
74+
}
75+
}
76+
77+
public function provideQueries()
78+
{
79+
return array(
80+
array(
81+
'query' => 'SELECT valves FROM [nt:unstructured]',
82+
),
83+
);
84+
}
85+
86+
public function provideProperties()
87+
{
88+
return array(
89+
array(
90+
'props' => array('valves'),
91+
),
92+
array(
93+
'props' => array('valves', 'thistles'),
94+
),
95+
array(
96+
'props' => array('valves', 'thistles', 'toppings', 'troikas'),
97+
),
98+
array(
99+
'props' => array('valves', 'thistles', 'toppings', 'troikas', 'underrate', 'worksheets'),
100+
),
101+
);
102+
}
103+
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
],
1111
"minimum-stability": "dev",
1212
"require": {
13-
"phpcr/phpcr-implementation": "~2.1",
1413
"dantleech/phpbench": "~1.0"
1514
},
1615
"autoload": {

0 commit comments

Comments
 (0)