2017-02-24 22:27:53 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Benchmarks;
|
2018-11-27 13:22:29 +03:00
|
|
|
|
2017-02-24 22:27:53 +03:00
|
|
|
use GraphQL\GraphQL;
|
|
|
|
use GraphQL\Tests\StarWarsSchema;
|
|
|
|
use GraphQL\Type\Introspection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @BeforeMethods({"setIntroQuery"})
|
|
|
|
* @OutputTimeUnit("milliseconds", precision=3)
|
|
|
|
* @Warmup(2)
|
|
|
|
* @Revs(10)
|
|
|
|
* @Iterations(2)
|
|
|
|
*/
|
|
|
|
class StarWarsBench
|
|
|
|
{
|
|
|
|
private $introQuery;
|
|
|
|
|
|
|
|
public function setIntroQuery()
|
|
|
|
{
|
|
|
|
$this->introQuery = Introspection::getIntrospectionQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function benchSchema()
|
|
|
|
{
|
|
|
|
StarWarsSchema::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function benchHeroQuery()
|
|
|
|
{
|
|
|
|
$q = '
|
|
|
|
query HeroNameQuery {
|
|
|
|
hero {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
';
|
|
|
|
|
2018-09-26 12:18:02 +03:00
|
|
|
GraphQL::executeQuery(
|
2017-02-24 22:27:53 +03:00
|
|
|
StarWarsSchema::build(),
|
|
|
|
$q
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function benchNestedQuery()
|
|
|
|
{
|
|
|
|
$q = '
|
|
|
|
query NestedQuery {
|
|
|
|
hero {
|
|
|
|
name
|
|
|
|
friends {
|
|
|
|
name
|
|
|
|
appearsIn
|
|
|
|
friends {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
';
|
2018-09-26 12:18:02 +03:00
|
|
|
GraphQL::executeQuery(
|
2017-02-24 22:27:53 +03:00
|
|
|
StarWarsSchema::build(),
|
|
|
|
$q
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function benchQueryWithFragment()
|
|
|
|
{
|
|
|
|
$q = '
|
|
|
|
query UseFragment {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
...HumanFragment
|
|
|
|
}
|
|
|
|
leia: human(id: "1003") {
|
|
|
|
...HumanFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment HumanFragment on Human {
|
|
|
|
name
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
';
|
|
|
|
|
2018-09-26 12:18:02 +03:00
|
|
|
GraphQL::executeQuery(
|
2017-02-24 22:27:53 +03:00
|
|
|
StarWarsSchema::build(),
|
|
|
|
$q
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function benchStarWarsIntrospectionQuery()
|
|
|
|
{
|
2018-09-26 12:18:02 +03:00
|
|
|
GraphQL::executeQuery(
|
2017-02-24 22:27:53 +03:00
|
|
|
StarWarsSchema::build(),
|
|
|
|
$this->introQuery
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|