diff --git a/tests/Benchmark/BasicImplementation/Aggregate/Profile.php b/tests/Benchmark/BasicImplementation/Aggregate/Profile.php index 875ed9b70..a62ce1cb2 100644 --- a/tests/Benchmark/BasicImplementation/Aggregate/Profile.php +++ b/tests/Benchmark/BasicImplementation/Aggregate/Profile.php @@ -10,6 +10,7 @@ use Patchlevel\EventSourcing\Attribute\Snapshot; use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\NameChanged; use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\ProfileCreated; +use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\Reborn; use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Normalizer\ProfileIdNormalizer; use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId; @@ -39,6 +40,14 @@ public function changeName(string $name): void $this->recordThat(new NameChanged($name)); } + public function reborn(): void + { + $this->recordThat(new Reborn( + $this->id, + $this->name + )); + } + #[Apply] protected function applyProfileCreated(ProfileCreated $event): void { @@ -52,6 +61,13 @@ protected function applyNameChanged(NameChanged $event): void $this->name = $event->name; } + #[Apply] + protected function applyReborn(Reborn $event): void + { + $this->id = $event->profileId; + $this->name = $event->name; + } + public function name(): string { return $this->name; diff --git a/tests/Benchmark/BasicImplementation/Events/Reborn.php b/tests/Benchmark/BasicImplementation/Events/Reborn.php new file mode 100644 index 000000000..e4d7e9ef2 --- /dev/null +++ b/tests/Benchmark/BasicImplementation/Events/Reborn.php @@ -0,0 +1,22 @@ + Driver::class, + 'path' => self::DB_PATH, + ]); + + $this->bus = new DefaultEventBus(); + + $this->store = new DoctrineDbalStore( + $connection, + DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']), + (new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']), + 'eventstore', + ); + + $this->repository = new DefaultRepository( + $this->store, + $this->bus, + Profile::metadata(), + null, + new SplitStreamDecorator( + new AttributeEventMetadataFactory() + ) + ); + + $schemaDirector = new DoctrineSchemaDirector( + $connection, + $this->store, + ); + + $schemaDirector->create(); + } + + public function provideData(): void + { + $profile = Profile::create(ProfileId::fromString('1'), 'Peter'); + + for ($i = 0; $i < 10_000; $i++) { + $profile->changeName(sprintf('Peter %d', $i)); + + if ($i % 100 === 0) { + $profile->reborn(); + } + } + + $this->repository->save($profile); + } + + #[Bench\Revs(20)] + #[Bench\BeforeMethods("provideData")] + public function benchLoad10000Events(): void + { + $this->repository->load('1'); + } + + #[Bench\Revs(20)] + public function benchWrite10000Events(): void + { + $profile = Profile::create(ProfileId::fromString('1'), 'Peter'); + + for ($i = 0; $i < 10_000; $i++) { + $profile->changeName(sprintf('Peter %d', $i)); + + if ($i % 100 === 0) { + $profile->reborn(); + } + } + + $this->repository->save($profile); + } +} diff --git a/tests/Benchmark/WriteEventsWithSyncProjectionistBench.php b/tests/Benchmark/SyncProjectionistBench.php similarity index 98% rename from tests/Benchmark/WriteEventsWithSyncProjectionistBench.php rename to tests/Benchmark/SyncProjectionistBench.php index ab691e939..028eec29c 100644 --- a/tests/Benchmark/WriteEventsWithSyncProjectionistBench.php +++ b/tests/Benchmark/SyncProjectionistBench.php @@ -33,7 +33,7 @@ use function unlink; #[Bench\BeforeMethods('setUp')] -final class WriteEventsWithSyncProjectionistBench +final class SyncProjectionistBench { private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';