Passed
Pull Request — main (#339)
by Chema
09:49 queued 05:35
created

bench_attribute_resolution_repeated()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Benchmark\DocBlockResolver;
6
7
use Gacela\Framework\DocBlockResolver\DocBlockResolverCache;
8
use Gacela\Framework\Gacela;
9
10
/**
11
 * @BeforeMethods("setUp")
12
 *
13
 * @AfterMethods("tearDown")
14
 */
15
final class DocBlockResolverBench
16
{
17
    public function setUp(): void
18
    {
19
        Gacela::bootstrap(__DIR__);
20
21
        DocBlockResolverCache::resetCache();
22
    }
23
24
    public function tearDown(): void
25
    {
26
        DocBlockResolverCache::resetCache();
27
    }
28
29
    /**
30
     * Benchmark attribute-based resolution.
31
     * Tests the fast path through searchClassOverAttributes().
32
     */
33
    public function bench_attribute_based_resolution(): void
34
    {
35
        $resolver = new DocBlockResolverAttributeBased();
36
        $resolver->getFactory();
37
    }
38
39
    /**
40
     * Benchmark PHPDoc-based resolution.
41
     * Tests the slower path through searchClassOverDocBlock() and string parsing.
42
     */
43
    public function bench_phpdoc_based_resolution(): void
44
    {
45
        $resolver = new DocBlockResolverPhpDocBased();
46
        $resolver->getFactory();
47
    }
48
49
    /**
50
     * Benchmark attribute resolution with repeated calls (tests caching).
51
     */
52
    public function bench_attribute_resolution_repeated(): void
53
    {
54
        $resolver = new DocBlockResolverAttributeBased();
55
        for ($i = 0; $i < 10; ++$i) {
56
            $resolver->getFactory();
57
        }
58
    }
59
60
    /**
61
     * Benchmark PHPDoc resolution with repeated calls (tests caching).
62
     */
63
    public function bench_phpdoc_resolution_repeated(): void
64
    {
65
        $resolver = new DocBlockResolverPhpDocBased();
66
        for ($i = 0; $i < 10; ++$i) {
67
            $resolver->getFactory();
68
        }
69
    }
70
}
71