Skip to content

Commit 2da9dd3

Browse files
committed
PoC
1 parent b8215d5 commit 2da9dd3

2 files changed

Lines changed: 39 additions & 186 deletions

File tree

tests/Benchmark/GeneratedHydratorBench.php

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,15 @@ final class GeneratedHydratorBench
2222

2323
public function __construct()
2424
{
25-
$metadataFactory = new AttributeMetadataFactory();
26-
27-
$classes = [
28-
ProfileCreated::class,
29-
ProfileId::class,
30-
Skill::class,
31-
];
32-
33-
$className = 'GeneratedTranformMiddleware';
34-
$fqcn = "Patchlevel\\Hydrator\\Tests\Benchmark\\" . $className;
35-
36-
$generator = new MiddlewareGenerator($metadataFactory);
37-
$code = $generator->dump($classes, $fqcn);
38-
39-
file_put_contents(__DIR__ . '/' . $className . '.php', $code);
40-
4125
$this->hydrator = (new HydratorBuilder())
42-
->addMiddleware(new $fqcn($metadataFactory))
43-
->addGuesser(new BuiltInGuesser(), -64)
26+
->useExtension(new GeneratedCoreExtension(
27+
__DIR__ . '/../../var/cache',
28+
[
29+
ProfileCreated::class,
30+
ProfileId::class,
31+
Skill::class,
32+
]
33+
))
4434
->build();
4535
}
4636

@@ -70,8 +60,21 @@ public function benchHydrate1Object(): void
7060
['name' => 'symfony'],
7161
],
7262
]);
63+
}
7364

65+
#[Bench\Revs(5)]
66+
public function benchExtract1Object(): void
67+
{
68+
$object = new ProfileCreated(
69+
ProfileId::fromString('1'),
70+
'foo',
71+
[
72+
new Skill('php'),
73+
new Skill('symfony'),
74+
],
75+
);
7476

77+
$this->hydrator->extract($object);
7578
}
7679

7780
#[Bench\Revs(3)]
@@ -88,6 +91,24 @@ public function benchHydrate1000Objects(): void
8891
]);
8992
}
9093
}
94+
95+
#[Bench\Revs(3)]
96+
public function benchExtract1000Objects(): void
97+
{
98+
$object = new ProfileCreated(
99+
ProfileId::fromString('1'),
100+
'foo',
101+
[
102+
new Skill('php'),
103+
new Skill('symfony'),
104+
],
105+
);
106+
107+
for ($i = 0; $i < 1_000; $i++) {
108+
$this->hydrator->extract($object);
109+
}
110+
}
111+
91112
#[Bench\Revs(3)]
92113
public function benchHydrate1000000Objects(): void
93114
{

tests/Benchmark/GeneratedTranformMiddleware.php

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)