From 69cb0f1f1d5accebd415521656827914b848b1d6 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 23 Mar 2024 03:44:09 +0300 Subject: [PATCH] Added memory reset function --- src/Services/Memory.php | 9 +++++++++ src/Services/Runner.php | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Services/Memory.php b/src/Services/Memory.php index 686edde..98574fb 100644 --- a/src/Services/Memory.php +++ b/src/Services/Memory.php @@ -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 { @@ -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) { diff --git a/src/Services/Runner.php b/src/Services/Runner.php index 7903a60..4e56176 100644 --- a/src/Services/Runner.php +++ b/src/Services/Runner.php @@ -4,7 +4,6 @@ namespace DragonCode\Benchmark\Services; -use function gc_collect_cycles; use function hrtime; class Runner @@ -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