Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Merge pull request #94 from yuloh/phpbench
Browse files Browse the repository at this point in the history
Add some benchmarks
  • Loading branch information
Matt A committed Feb 5, 2017
2 parents 469d5c0 + ed8ddb3 commit 18a6715
Show file tree
Hide file tree
Showing 10 changed files with 1,736 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -9,3 +9,4 @@
/.scrutinizer.yml export-ignore
/tests export-ignore
/docs export-ignore
phpbench.json export-ignore
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -58,15 +58,17 @@
},
"autoload-dev": {
"psr-4": {
"League\\JsonGuard\\Test\\": "tests"
"League\\JsonGuard\\Test\\": "tests",
"League\\JsonGuard\\Bench\\": "tests/benchmarks"
},
"files": [
"tests/helpers.php"
]
},
"scripts": {
"test": "phpunit",
"cs": "phpcs --standard=psr2 src/"
"cs": "phpcs --standard=psr2 src/",
"bench": "phpbench run ./tests/benchmarks --report=default"
},
"extra": {
"branch-alias": {
Expand Down
3 changes: 3 additions & 0 deletions phpbench.json
@@ -0,0 +1,3 @@
{
"bootstrap": "vendor/autoload.php"
}
20 changes: 20 additions & 0 deletions tests/benchmarks/Benchmark.php
@@ -0,0 +1,20 @@
<?php

namespace League\JsonGuard\Bench;

/**
* @BeforeMethods({"setUp"})
* @AfterMethods({"tearDown"})
*/
abstract class Benchmark
{
public function setUp()
{

}

public function tearDown()
{

}
}
26 changes: 26 additions & 0 deletions tests/benchmarks/DereferenceBenchmark.php
@@ -0,0 +1,26 @@
<?php

namespace League\JsonGuard\Bench;

use League\JsonGuard\Dereferencer;

/**
* @Groups({"dereference"})
* @Revs(100)
*/
abstract class DereferenceBenchmark extends Benchmark
{
protected $schema;

abstract public function getSchema();

public function setUp()
{
$this->schema = $this->getSchema();
}

public function benchJsonGuard()
{
(new Dereferencer())->dereference($this->schema);
}
}
11 changes: 11 additions & 0 deletions tests/benchmarks/MetaSchemaDereferenceBench.php
@@ -0,0 +1,11 @@
<?php

namespace League\JsonGuard\Bench;

class MetaSchemaDereferenceBench extends DereferenceBenchmark
{
public function getSchema()
{
return json_decode(file_get_contents(__DIR__ . '/../fixtures/draft4-schema.json'));
}
}
16 changes: 16 additions & 0 deletions tests/benchmarks/MetaSchemaValidationBench.php
@@ -0,0 +1,16 @@
<?php

namespace League\JsonGuard\Bench;

class MetaSchemaValidationBench extends ValidationBenchmark
{
public function getData()
{
return $this->getSchema();
}

public function getSchema()
{
return json_decode(file_get_contents(__DIR__ . '/../fixtures/draft4-schema.json'));
}
}
16 changes: 16 additions & 0 deletions tests/benchmarks/SwaggerValidationBench.php
@@ -0,0 +1,16 @@
<?php

namespace League\JsonGuard\Bench;

class SwaggerValidationBench extends ValidationBenchmark
{
public function getData()
{
return json_decode(file_get_contents(__DIR__ . '/../fixtures/swagger2.json'));
}

public function getSchema()
{
return json_decode(file_get_contents(__DIR__ . '/../fixtures/draft4-schema.json'));
}
}
32 changes: 32 additions & 0 deletions tests/benchmarks/ValidationBenchmark.php
@@ -0,0 +1,32 @@
<?php

namespace League\JsonGuard\Bench;

use League\JsonGuard\Dereferencer;
use League\JsonGuard\Validator;

/**
* @Groups({"validation"})
* @Revs(100)
*/
abstract class ValidationBenchmark extends Benchmark
{
protected $data;

protected $schema;

abstract public function getData();

abstract public function getSchema();

public function setUp()
{
$this->data = $this->getData();
$this->schema = (new Dereferencer())->dereference($this->getSchema());
}

public function benchJsonGuard()
{
(new Validator($this->data, $this->schema))->errors();
}
}

0 comments on commit 18a6715

Please sign in to comment.