This commit is contained in:
2026-01-22 01:59:03 +03:00
parent a174e0d5ab
commit 3fa7b17de9
+12 -17
View File
@@ -53,22 +53,7 @@ class Benchmark:
self.name = name
self.description = description
def single_run(self, is_gc_disabled: bool = False) -> float:
if is_gc_disabled:
was_gc_enabled = gc.isenabled()
gc.disable()
with redirect_stdout(io.StringIO()):
start = time.perf_counter()
self.func()
end = time.perf_counter()
if was_gc_enabled:
gc.enable()
gc.collect()
return (end - start) * MILLISECONDS_IN_SECONDS
else:
def single_run(self) -> float:
with redirect_stdout(io.StringIO()):
start = time.perf_counter()
self.func()
@@ -77,8 +62,18 @@ class Benchmark:
def multiple_runs(self, iterations: int, is_gc_disabled: bool = False) -> tuple[float, ...]:
run_attempts: list[float] = []
if is_gc_disabled:
was_gc_enabled = gc.isenabled()
gc.disable()
for _ in range(iterations):
run_attempts.append(self.single_run(is_gc_disabled))
run_attempts.append(self.single_run())
if was_gc_enabled:
gc.enable()
gc.collect()
return tuple(run_attempts)
else:
for _ in range(iterations):
run_attempts.append(self.single_run())
return tuple(run_attempts)
@override