Skip to content

Commit

Permalink
Add used memory to output
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrokeil committed Jul 26, 2020
1 parent 259cf3f commit 0be21e3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/AllProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function run()
$avg = $this->stopAt / $time;

outputText("Projection $this->id read $readEvents events");
outputText("Projection $this->id used $time seconds, avg $avg events/second");
outputText("Projection $this->id used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Projection $this->id checking integrity ...", true, '');
Assertion::eq($readEvents, $stopAt, 'Number of all projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
Expand Down
2 changes: 1 addition & 1 deletion src/CategoryProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function run()
$avg = $this->stopAt / $time;

outputText("Projection $this->id read $readEvents events");
outputText("Projection $this->id used $time seconds, avg $avg events/second");
outputText("Projection $this->id used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Projection $this->id checking integrity ...", true, '');
Assertion::eq($readEvents, 2500, 'Number of category projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
Expand Down
2 changes: 1 addition & 1 deletion src/StreamCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function run()
$avg = ($this->executions * $this->numberOfEvents) / $time;

outputText("Writer $this->id-$this->category wrote $this->eventsWritten events");
outputText("Writer $this->id-$this->category used $time seconds, avg $avg events/second");
outputText("Writer $this->id-$this->category used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Writer $this->id checking integrity ...", true, '');
Assertion::eq($count, $this->numberOfEvents * $this->executions, 'Number of writer events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
Expand Down
1 change: 1 addition & 0 deletions src/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,5 @@
outputText('test 6 checking integrity ...', true, '');
Assertion::eq($projection->getState()['count'], 1000, 'Number of projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
outputText( "Mem usage/peak: " . getMemoryConsumption() . PHP_EOL, false);
}
8 changes: 8 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,11 @@ function getStreamHandlerFactory(): StreamHandlerFactoryInterface
{
return new ArrayStreamHandlerFactory();
}

function getMemoryConsumption(): string
{
$memUsage = memory_get_usage();
$memPeak = memory_get_peak_usage();

return '(' . round($memUsage / 1024 / 1024, 2) . 'MB / ' . round($memPeak / 1024 / 1024, 2) . ' MB)';
}

0 comments on commit 0be21e3

Please sign in to comment.