-
-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathHugeSchemaBench.php
More file actions
77 lines (64 loc) · 1.76 KB
/
HugeSchemaBench.php
File metadata and controls
77 lines (64 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php declare(strict_types=1);
namespace GraphQL\Benchmarks;
use GraphQL\Benchmarks\Utils\QueryGenerator;
use GraphQL\Benchmarks\Utils\SchemaGenerator;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use GraphQL\Type\SchemaConfig;
/**
* @BeforeMethods({"setUp"})
*
* @OutputTimeUnit("milliseconds", precision=3)
*
* @Warmup(1)
*
* @Revs(5)
*
* @Iterations(1)
*/
class HugeSchemaBench
{
private SchemaGenerator $schemaGenerator;
private Schema $schema;
private string $smallQuery;
public function setUp(): void
{
$this->schemaGenerator = new SchemaGenerator([
'totalTypes' => 600,
'fieldsPerType' => 8,
'listFieldsPerType' => 2,
'nestingLevel' => 10,
]);
$this->schema = $this->schemaGenerator->buildSchema();
$queryBuilder = new QueryGenerator($this->schema, 0.05);
$this->smallQuery = $queryBuilder->buildQuery();
}
public function benchSchema(): void
{
$this->schemaGenerator
->buildSchema()
->getTypeMap();
}
public function benchSchemaLazy(): void
{
$this->createLazySchema();
}
public function benchSmallQuery(): void
{
GraphQL::executeQuery($this->schema, $this->smallQuery);
}
public function benchSmallQueryLazy(): void
{
$schema = $this->createLazySchema();
GraphQL::executeQuery($schema, $this->smallQuery);
}
private function createLazySchema(): Schema
{
return new Schema(
(new SchemaConfig())
->setQuery($this->schemaGenerator->buildQueryType())
->setTypeLoader(fn (string $name): Type => $this->schemaGenerator->loadType($name))
);
}
}