Skip to content

Commit

Permalink
Added memory reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Mar 23, 2024
1 parent 400b687 commit 69cb0f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Services/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace DragonCode\Benchmark\Services;

use function gc_collect_cycles;
use function memory_get_peak_usage;
use function memory_reset_peak_usage;
use function sprintf;

class Memory
{
Expand All @@ -24,6 +27,12 @@ public function diff(int $memory): int
return memory_get_peak_usage(true) - $memory;
}

public function reset(): void
{
gc_collect_cycles();
memory_reset_peak_usage();
}

public function format(int $bytes): string
{
foreach ($this->sizes as $unit => $value) {
Expand Down
3 changes: 1 addition & 2 deletions src/Services/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace DragonCode\Benchmark\Services;

use function gc_collect_cycles;
use function hrtime;

class Runner
Expand All @@ -22,7 +21,7 @@ public function call(callable $callback, array $parameters = []): array

protected function clean(): void
{
gc_collect_cycles();
$this->memory->reset();
}

protected function run(callable $callback, array $parameters = []): array
Expand Down

0 comments on commit 69cb0f1

Please sign in to comment.