Passed
Pull Request — main (#339)
by Chema
05:43 queued 01:20
created

bench_phpdoc_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
        // Bootstrap Gacela on first run
20
        Gacela::bootstrap(__DIR__);
21
22
        // Clear cache before each benchmark to measure actual resolution time
23
        DocBlockResolverCache::resetCache();
24
    }
25
26
    public function tearDown(): void
27
    {
28
        // Clear cache after each benchmark
29
        DocBlockResolverCache::resetCache();
30
    }
31
32
    /**
33
     * Benchmark attribute-based resolution.
34
     * Tests the fast path through searchClassOverAttributes().
35
     */
36
    public function bench_attribute_based_resolution(): void
37
    {
38
        $resolver = new DocBlockResolverAttributeBased();
39
        $resolver->getFactory();
40
    }
41
42
    /**
43
     * Benchmark PHPDoc-based resolution.
44
     * Tests the slower path through searchClassOverDocBlock() and string parsing.
45
     */
46
    public function bench_phpdoc_based_resolution(): void
47
    {
48
        $resolver = new DocBlockResolverPhpDocBased();
49
        $resolver->getFactory();
50
    }
51
52
    /**
53
     * Benchmark attribute resolution with repeated calls (tests caching).
54
     */
55
    public function bench_attribute_resolution_repeated(): void
56
    {
57
        $resolver = new DocBlockResolverAttributeBased();
58
        for ($i = 0; $i < 10; ++$i) {
59
            $resolver->getFactory();
60
        }
61
    }
62
63
    /**
64
     * Benchmark PHPDoc resolution with repeated calls (tests caching).
65
     */
66
    public function bench_phpdoc_resolution_repeated(): void
67
    {
68
        $resolver = new DocBlockResolverPhpDocBased();
69
        for ($i = 0; $i < 10; ++$i) {
70
            $resolver->getFactory();
71
        }
72
    }
73
}
74