-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmarks (Graph vs. native SimpleXML)
- Loading branch information
Showing
13 changed files
with
472 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark; | ||
|
||
use RuntimeException; | ||
|
||
abstract class BaseCase | ||
{ | ||
/** | ||
* @param $expected | ||
* @param $actual | ||
* @throws RuntimeException | ||
*/ | ||
protected function assertSame($expected, $actual) | ||
{ | ||
if ($expected !== $actual) { | ||
throw new RuntimeException(sprintf('Expected `%s` but got `%s`.', $expected, $actual)); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @return string | ||
*/ | ||
protected function getAssetFile($file) | ||
{ | ||
return dirname(__DIR__) . '/assets/' . $file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark\Graph; | ||
|
||
use Rayne\wz2008\Graph\Benchmark\InitializationCase; | ||
use Rayne\wz2008\Graph\Factory\WzClassificationFactory; | ||
|
||
class GraphInitializationBench extends InitializationCase | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function benchInitialization() | ||
{ | ||
WzClassificationFactory::build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark\Graph; | ||
|
||
use Rayne\wz2008\Graph\Benchmark\ParentItemAccessCase; | ||
use Rayne\wz2008\Graph\Factory\WzClassificationFactory; | ||
use Rayne\wz2008\Graph\WzClassificationInterface; | ||
use Rayne\wz2008\Graph\WzItemInterface; | ||
|
||
class GraphParentItemAccessBench extends ParentItemAccessCase | ||
{ | ||
/** | ||
* @var null|WzItemInterface | ||
*/ | ||
private $child; | ||
|
||
/** | ||
* @var WzClassificationInterface | ||
*/ | ||
private $graph; | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->graph = WzClassificationFactory::build(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function benchColdParentItemAccess(array $params) | ||
{ | ||
$this->assertSame( | ||
$params['parent'], | ||
$this->graph->get($params['child'])->getParent()->getId()); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function beforeWarmParentItemAccess(array $params) | ||
{ | ||
$this->child = $this->graph->get($params['child']); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function benchWarmParentItemAccess(array $params) | ||
{ | ||
$this->assertSame( | ||
$params['parent'], | ||
$this->child->getParent()->getId()); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function afterWarmParentItemAccess(array $params) | ||
{ | ||
$this->child = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark\Graph; | ||
|
||
use Rayne\wz2008\Graph\Benchmark\RandomItemAccessCase; | ||
use Rayne\wz2008\Graph\Factory\WzClassificationFactory; | ||
use Rayne\wz2008\Graph\WzClassificationInterface; | ||
|
||
class GraphRandomItemAccessBench extends RandomItemAccessCase | ||
{ | ||
/** | ||
* @var WzClassificationInterface | ||
*/ | ||
public $graph; | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->graph = WzClassificationFactory::build(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function benchRandomItemAccess($params) | ||
{ | ||
$this->assertSame($params['child'], $this->graph->get('id')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Groups; | ||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
|
||
abstract class InitializationCase extends BaseCase | ||
{ | ||
/** | ||
* @Groups({"Initialization"}) | ||
* | ||
* @Warmup(1) | ||
* @Revs(33) | ||
* @Iterations(3) | ||
*/ | ||
abstract public function benchInitialization(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\AfterMethods; | ||
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; | ||
use PhpBench\Benchmark\Metadata\Annotations\Groups; | ||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\ParamProviders; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
|
||
abstract class ParentItemAccessCase extends BaseCase | ||
{ | ||
/** | ||
* @return array[] | ||
*/ | ||
public function provideChildAndParentIds() | ||
{ | ||
return [ | ||
['child' => '74.10.2', 'parent' => '74.10'], | ||
['child' => '74.10', 'parent' => '74.1'], | ||
['child' => '74.1', 'parent' => '74'], | ||
['child' => '74', 'parent' => 'M'], | ||
]; | ||
} | ||
|
||
/** | ||
* @Groups({"Parent Access"}) | ||
* @ParamProviders({"provideChildAndParentIds"}) | ||
* | ||
* @Warmup(1) | ||
* @Revs(33) | ||
* @Iterations(3) | ||
* | ||
* @param array $params | ||
*/ | ||
abstract public function benchColdParentItemAccess(array $params); | ||
|
||
/** | ||
* @param array $params | ||
*/ | ||
abstract public function beforeWarmParentItemAccess(array $params); | ||
|
||
/** | ||
* @Groups({"Parent Access"}) | ||
* @ParamProviders({"provideChildAndParentIds"}) | ||
* @BeforeMethods({"beforeWarmParentItemAccess"}) | ||
* @AfterMethods({"afterWarmParentItemAccess"}) | ||
* | ||
* @Warmup(1) | ||
* @Revs(33) | ||
* @Iterations(3) | ||
* | ||
* @param array $params | ||
*/ | ||
abstract public function benchWarmParentItemAccess(array $params); | ||
|
||
/** | ||
* @param array $params | ||
*/ | ||
abstract public function afterWarmParentItemAccess(array $params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark; | ||
|
||
use PhpBench\Benchmark\Metadata\Annotations\Groups; | ||
use PhpBench\Benchmark\Metadata\Annotations\Iterations; | ||
use PhpBench\Benchmark\Metadata\Annotations\ParamProviders; | ||
use PhpBench\Benchmark\Metadata\Annotations\Revs; | ||
use PhpBench\Benchmark\Metadata\Annotations\Warmup; | ||
|
||
abstract class RandomItemAccessCase extends BaseCase | ||
{ | ||
/** | ||
* @Groups({"Random Access"}) | ||
* @ParamProviders({"provideRandomItemAccessIds"}) | ||
* | ||
* @Warmup(1) | ||
* @Revs(33) | ||
* @Iterations(3) | ||
* | ||
* @param $params | ||
*/ | ||
abstract public function benchRandomItemAccess($params); | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function provideRandomItemAccessIds() | ||
{ | ||
$result = []; | ||
|
||
foreach (range('A', 'U') as $levelOneId) { | ||
$result[] = ['id' => $levelOneId]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* (c) Dennis Meckel | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rayne\wz2008\Graph\Benchmark\Graph; | ||
|
||
use Rayne\wz2008\Graph\Benchmark\InitializationCase; | ||
|
||
class SimpleXmlInitializationBench extends InitializationCase | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function benchInitialization() | ||
{ | ||
simplexml_load_file($this->getAssetFile('WZ2008-2016-07-29-Classification_(complete).xml')); | ||
} | ||
} |
Oops, something went wrong.