Skip to content

Commit

Permalink
improve setup for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed May 3, 2022
1 parent c497d30 commit f95b22b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions tests/Benchmark/LoadEventsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@ final class LoadEventsBench

private Store $store;
private EventBus $bus;
private Repository $repository;

public function setUp(): void
{
Expand All @@ -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);
Expand All @@ -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');
}
}
10 changes: 5 additions & 5 deletions tests/Benchmark/LoadEventsWithSnapshotsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ final class LoadEventsWithSnapshotsBench
private Store $store;
private EventBus $bus;
private SnapshotStore $snapshotStore;
private Repository $repository;

public function setUp(): void
{
Expand All @@ -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);
Expand All @@ -66,16 +68,14 @@ public function setUp(): void
$profile->changeName('Peter');
}

$repository->save($profile);
$this->repository->save($profile);
$this->snapshotStore->save($profile);
}

#[Bench\Revs(10)]
#[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');
}
}

0 comments on commit f95b22b

Please sign in to comment.