Issues (162)

benchmarks/HugeSchemaBench.php (2 issues)

1
<?php
2
namespace GraphQL\Benchmarks;
3
4
use GraphQL\Benchmarks\Utils\QueryGenerator;
5
use GraphQL\Benchmarks\Utils\SchemaGenerator;
6
use GraphQL\GraphQL;
7
use GraphQL\Type\Schema;
8
use GraphQL\Type\SchemaConfig;
9
10
/**
11
 * @BeforeMethods({"setUp"})
12
 * @OutputTimeUnit("milliseconds", precision=3)
13
 * @Warmup(1)
14
 * @Revs(5)
15
 * @Iterations(1)
16
 */
17
class HugeSchemaBench
18
{
19
    /** @var SchemaGenerator */
20
    private $schemaBuilder;
21
22
    private $schema;
23
24
    /** @var string */
25
    private $smallQuery;
26
27
    public function setUp()
28
    {
29
        $this->schemaBuilder = new SchemaGenerator([
30
            'totalTypes' => 600,
31
            'fieldsPerType' => 8,
32
            'listFieldsPerType' => 2,
33
            'nestingLevel' => 10,
34
        ]);
35
36
        $this->schema = $this->schemaBuilder->buildSchema();
37
38
        $queryBuilder     = new QueryGenerator($this->schema, 0.05);
39
        $this->smallQuery = $queryBuilder->buildQuery();
40
    }
41
42
    public function benchSchema()
43
    {
44
        $this->schemaBuilder
45
            ->buildSchema()
46
            ->getTypeMap();
47
    }
48
49
    public function benchSchemaLazy()
50
    {
51
        $this->createLazySchema();
52
    }
53
54
    public function benchSmallQuery()
55
    {
56
        $result = GraphQL::executeQuery($this->schema, $this->smallQuery);
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
57
    }
58
59
    public function benchSmallQueryLazy()
60
    {
61
        $schema = $this->createLazySchema();
62
        $result = GraphQL::executeQuery($schema, $this->smallQuery);
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
63
    }
64
65
    private function createLazySchema()
66
    {
67
        return new Schema(
68
            SchemaConfig::create()
69
                ->setQuery($this->schemaBuilder->buildQueryType())
70
                ->setTypeLoader(function ($name) {
71
                    return $this->schemaBuilder->loadType($name);
72
                })
73
        );
74
    }
75
}
76