Skip to content

Commit 69cb0f1

Browse files
Added memory reset function
1 parent 400b687 commit 69cb0f1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Services/Memory.php

+9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace DragonCode\Benchmark\Services;
66

7+
use function gc_collect_cycles;
78
use function memory_get_peak_usage;
9+
use function memory_reset_peak_usage;
10+
use function sprintf;
811

912
class Memory
1013
{
@@ -24,6 +27,12 @@ public function diff(int $memory): int
2427
return memory_get_peak_usage(true) - $memory;
2528
}
2629

30+
public function reset(): void
31+
{
32+
gc_collect_cycles();
33+
memory_reset_peak_usage();
34+
}
35+
2736
public function format(int $bytes): string
2837
{
2938
foreach ($this->sizes as $unit => $value) {

src/Services/Runner.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace DragonCode\Benchmark\Services;
66

7-
use function gc_collect_cycles;
87
use function hrtime;
98

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

2322
protected function clean(): void
2423
{
25-
gc_collect_cycles();
24+
$this->memory->reset();
2625
}
2726

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

0 commit comments

Comments
 (0)