mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
benchs
This commit is contained in:
@@ -53,33 +53,28 @@ class Benchmark:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
def single_run(self, is_gc_disabled: bool = False) -> float:
|
def single_run(self) -> float:
|
||||||
if is_gc_disabled:
|
with redirect_stdout(io.StringIO()):
|
||||||
was_gc_enabled = gc.isenabled()
|
start = time.perf_counter()
|
||||||
gc.disable()
|
self.func()
|
||||||
|
end = time.perf_counter()
|
||||||
with redirect_stdout(io.StringIO()):
|
return (end - start) * MILLISECONDS_IN_SECONDS
|
||||||
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:
|
|
||||||
with redirect_stdout(io.StringIO()):
|
|
||||||
start = time.perf_counter()
|
|
||||||
self.func()
|
|
||||||
end = time.perf_counter()
|
|
||||||
return (end - start) * MILLISECONDS_IN_SECONDS
|
|
||||||
|
|
||||||
def multiple_runs(self, iterations: int, is_gc_disabled: bool = False) -> tuple[float, ...]:
|
def multiple_runs(self, iterations: int, is_gc_disabled: bool = False) -> tuple[float, ...]:
|
||||||
run_attempts: list[float] = []
|
run_attempts: list[float] = []
|
||||||
for _ in range(iterations):
|
if is_gc_disabled:
|
||||||
run_attempts.append(self.single_run(is_gc_disabled))
|
was_gc_enabled = gc.isenabled()
|
||||||
return tuple(run_attempts)
|
gc.disable()
|
||||||
|
for _ in range(iterations):
|
||||||
|
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
|
@override
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user