Skip to content

Commit

Permalink
improve benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 13, 2023
1 parent 17afc2f commit 6134991
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 109 deletions.
11 changes: 6 additions & 5 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,31 @@
<code>$name</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Benchmark/LoadEventsBench.php">
<file src="tests/Benchmark/SimpleSetupBench.php">
<MissingConstructor>
<code>$bus</code>
<code>$repository</code>
<code>$store</code>
</MissingConstructor>
</file>
<file src="tests/Benchmark/LoadEventsWithSnapshotsBench.php">
<file src="tests/Benchmark/SnapshotsBench.php">
<MissingConstructor>
<code>$adapter</code>
<code>$bus</code>
<code>$repository</code>
<code>$snapshotStore</code>
<code>$store</code>
</MissingConstructor>
</file>
<file src="tests/Benchmark/WriteEventsBench.php">
<file src="tests/Benchmark/SplitStreamBench.php">
<MissingConstructor>
<code>$bus</code>
<code>$profile</code>
<code>$repository</code>
<code>$snapshotStore</code>
<code>$store</code>
</MissingConstructor>
</file>
<file src="tests/Benchmark/WriteEventsWithSyncProjectionistBench.php">
<file src="tests/Benchmark/SyncProjectionistBench.php">
<MissingConstructor>
<code>$bus</code>
<code>$profile</code>
Expand Down
5 changes: 5 additions & 0 deletions src/Snapshot/Adapter/InMemorySnapshotAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public function load(string $key): array

return $this->snapshots[$key];
}

public function clear(): void
{
$this->snapshots = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use function unlink;

#[Bench\BeforeMethods('setUp')]
final class LoadEventsBench
final class SimpleSetupBench
{
private const DB_PATH = __DIR__ . '/BasicImplementation/data/db.sqlite3';

Expand Down Expand Up @@ -74,4 +74,23 @@ public function benchLoad10000Events(): void
{
$this->repository->load('1');
}

#[Bench\Revs(20)]
public function benchSave1Event(): void
{
$profile = Profile::create(ProfileId::generate(), 'Peter');
$this->repository->save($profile);
}

#[Bench\Revs(20)]
public function benchSave10000Events(): void
{
$profile = Profile::create(ProfileId::generate(), 'Peter');

for ($i = 1; $i < 10_000; $i++) {
$profile->changeName('Peter');
}

$this->repository->save($profile);
}
}
13 changes: 12 additions & 1 deletion tests/Benchmark/SnapshotsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ final class SnapshotsBench
private SnapshotStore $snapshotStore;
private Repository $repository;

private InMemorySnapshotAdapter $adapter;

public function setUp(): void
{
if (file_exists(self::DB_PATH)) {
Expand All @@ -55,7 +57,9 @@ public function setUp(): void
'eventstore',
);

$this->snapshotStore = new DefaultSnapshotStore(['default' => new InMemorySnapshotAdapter()]);
$this->adapter = new InMemorySnapshotAdapter();

$this->snapshotStore = new DefaultSnapshotStore(['default' => $this->adapter]);

$this->repository = new DefaultRepository($this->store, $this->bus, Profile::metadata(), $this->snapshotStore);

Expand All @@ -76,6 +80,13 @@ public function setUp(): void
$this->snapshotStore->save($profile);
}

#[Bench\Revs(20)]
public function benchLoad10000EventsMissingSnapshot(): void
{
$this->adapter->clear();
$this->repository->load('1');
}

#[Bench\Revs(20)]
public function benchLoad10000Events(): void
{
Expand Down
102 changes: 0 additions & 102 deletions tests/Benchmark/WriteEventsBench.php

This file was deleted.

0 comments on commit 6134991

Please sign in to comment.