Passed
Push — master ( e7bef7...3228c5 )
by Vladimir
03:06
created

StarWarsBench   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 81
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A benchHeroQuery() 0 13 1
A benchStarWarsIntrospectionQuery() 0 5 1
A setIntroQuery() 0 3 1
A benchSchema() 0 3 1
A benchNestedQuery() 0 19 1
A benchQueryWithFragment() 0 21 1
1
<?php
2
namespace GraphQL\Benchmarks;
3
4
use GraphQL\GraphQL;
5
use GraphQL\Tests\StarWarsSchema;
6
use GraphQL\Type\Introspection;
7
8
/**
9
 * @BeforeMethods({"setIntroQuery"})
10
 * @OutputTimeUnit("milliseconds", precision=3)
11
 * @Warmup(2)
12
 * @Revs(10)
13
 * @Iterations(2)
14
 */
15
class StarWarsBench
16
{
17
    private $introQuery;
18
19
    public function setIntroQuery()
20
    {
21
        $this->introQuery = Introspection::getIntrospectionQuery();
22
    }
23
24
    public function benchSchema()
25
    {
26
        StarWarsSchema::build();
27
    }
28
29
    public function benchHeroQuery()
30
    {
31
        $q = '
32
        query HeroNameQuery {
33
          hero {
34
            name
35
          }
36
        }
37
        ';
38
39
        GraphQL::executeQuery(
40
            StarWarsSchema::build(),
41
            $q
42
        );
43
    }
44
45
    public function benchNestedQuery()
46
    {
47
        $q = '
48
        query NestedQuery {
49
          hero {
50
            name
51
            friends {
52
              name
53
              appearsIn
54
              friends {
55
                name
56
              }
57
            }
58
          }
59
        }
60
        ';
61
        GraphQL::executeQuery(
62
            StarWarsSchema::build(),
63
            $q
64
        );
65
    }
66
67
    public function benchQueryWithFragment()
68
    {
69
        $q = '
70
        query UseFragment {
71
          luke: human(id: "1000") {
72
            ...HumanFragment
73
          }
74
          leia: human(id: "1003") {
75
            ...HumanFragment
76
          }
77
        }
78
79
        fragment HumanFragment on Human {
80
          name
81
          homePlanet
82
        }
83
        ';
84
85
        GraphQL::executeQuery(
86
            StarWarsSchema::build(),
87
            $q
88
        );
89
    }
90
91
    public function benchStarWarsIntrospectionQuery()
92
    {
93
        GraphQL::executeQuery(
94
            StarWarsSchema::build(),
95
            $this->introQuery
96
        );
97
    }
98
}
99