From f95b22bb8c67bba6b9700aed89b304ec2aebaa7c Mon Sep 17 00:00:00 2001 From: David Badura Date: Tue, 3 May 2022 13:12:24 +0200 Subject: [PATCH] improve setup for benchmarks --- tests/Benchmark/LoadEventsBench.php | 10 +++++----- tests/Benchmark/LoadEventsWithSnapshotsBench.php | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Benchmark/LoadEventsBench.php b/tests/Benchmark/LoadEventsBench.php index 5b45a3c5d..6d074761f 100644 --- a/tests/Benchmark/LoadEventsBench.php +++ b/tests/Benchmark/LoadEventsBench.php @@ -10,6 +10,7 @@ use Patchlevel\EventSourcing\EventBus\EventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; +use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager; use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; use Patchlevel\EventSourcing\Store\SingleTableStore; @@ -28,6 +29,7 @@ final class LoadEventsBench private Store $store; private EventBus $bus; + private Repository $repository; public function setUp(): void { @@ -49,7 +51,7 @@ public function setUp(): void 'eventstore' ); - $repository = new DefaultRepository($this->store, $this->bus, Profile::class); + $this->repository = new DefaultRepository($this->store, $this->bus, Profile::class); // create tables (new DoctrineSchemaManager())->create($this->store); @@ -60,15 +62,13 @@ public function setUp(): void $profile->changeName('Peter'); } - $repository->save($profile); + $this->repository->save($profile); } #[Bench\Revs(10)] #[Bench\Iterations(2)] public function benchLoadEvents(): void { - $repository = new DefaultRepository($this->store, $this->bus, Profile::class); - - $repository->load('1'); + $this->repository->load('1'); } } diff --git a/tests/Benchmark/LoadEventsWithSnapshotsBench.php b/tests/Benchmark/LoadEventsWithSnapshotsBench.php index 5893f5ba3..244cbca49 100644 --- a/tests/Benchmark/LoadEventsWithSnapshotsBench.php +++ b/tests/Benchmark/LoadEventsWithSnapshotsBench.php @@ -10,6 +10,7 @@ use Patchlevel\EventSourcing\EventBus\EventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; +use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager; use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; use Patchlevel\EventSourcing\Snapshot\Adapter\InMemorySnapshotAdapter; @@ -32,6 +33,7 @@ final class LoadEventsWithSnapshotsBench private Store $store; private EventBus $bus; private SnapshotStore $snapshotStore; + private Repository $repository; public function setUp(): void { @@ -55,7 +57,7 @@ public function setUp(): void $this->snapshotStore = new DefaultSnapshotStore(['default' => new InMemorySnapshotAdapter()]); - $repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); + $this->repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); // create tables (new DoctrineSchemaManager())->create($this->store); @@ -66,7 +68,7 @@ public function setUp(): void $profile->changeName('Peter'); } - $repository->save($profile); + $this->repository->save($profile); $this->snapshotStore->save($profile); } @@ -74,8 +76,6 @@ public function setUp(): void #[Bench\Iterations(2)] public function benchLoadEvents(): void { - $repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); - - $repository->load('1'); + $this->repository->load('1'); } }