graphql-php/benchmarks/HugeSchemaBench.php

76 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace GraphQL\Benchmarks;
use GraphQL\Benchmarks\Utils\QueryGenerator;
use GraphQL\Benchmarks\Utils\SchemaGenerator;
2018-11-27 13:22:29 +03:00
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
2018-11-27 13:22:29 +03:00
use GraphQL\Type\SchemaConfig;
/**
* @BeforeMethods({"setUp"})
* @OutputTimeUnit("milliseconds", precision=3)
* @Warmup(1)
* @Revs(5)
* @Iterations(1)
*/
class HugeSchemaBench
{
2018-11-27 13:22:29 +03:00
/** @var SchemaGenerator */
private $schemaBuilder;
private $schema;
2018-11-27 13:22:29 +03:00
/** @var string */
private $smallQuery;
public function setUp()
{
$this->schemaBuilder = new SchemaGenerator([
'totalTypes' => 600,
'fieldsPerType' => 8,
'listFieldsPerType' => 2,
2018-11-27 13:22:29 +03:00
'nestingLevel' => 10,
]);
$this->schema = $this->schemaBuilder->buildSchema();
2018-11-27 13:22:29 +03:00
$queryBuilder = new QueryGenerator($this->schema, 0.05);
$this->smallQuery = $queryBuilder->buildQuery();
}
public function benchSchema()
{
$this->schemaBuilder
->buildSchema()
2018-11-27 13:22:29 +03:00
->getTypeMap();
}
public function benchSchemaLazy()
{
$this->createLazySchema();
}
public function benchSmallQuery()
{
2018-09-26 12:18:02 +03:00
$result = GraphQL::executeQuery($this->schema, $this->smallQuery);
}
public function benchSmallQueryLazy()
{
$schema = $this->createLazySchema();
2018-09-26 12:18:02 +03:00
$result = GraphQL::executeQuery($schema, $this->smallQuery);
}
private function createLazySchema()
{
return new Schema(
2018-11-27 13:22:29 +03:00
SchemaConfig::create()
->setQuery($this->schemaBuilder->buildQueryType())
2018-11-27 13:22:29 +03:00
->setTypeLoader(function ($name) {
return $this->schemaBuilder->loadType($name);
})
);
}
}