mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
pretty gifff
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .benchmarks.pre_cycle_setup import *
|
||||
+10
-1
@@ -1,10 +1,19 @@
|
||||
from metrics.utils import attempts_to_average
|
||||
from .registry import Benchmarks, Benchmark
|
||||
|
||||
|
||||
def main():
|
||||
all_benchmarks: list[Benchmark] = Benchmarks.get_benchmarks()
|
||||
|
||||
for benchmark in all_benchmarks: pass
|
||||
for benchmark in all_benchmarks:
|
||||
bench_attempts: list[float] = []
|
||||
for _ in range(benchmark.iterations):
|
||||
bench_attempts.append(benchmark.run())
|
||||
|
||||
print(f'Name: {benchmark.name}\n'
|
||||
f'Description: {benchmark.description}\n'
|
||||
f'Iterations: {benchmark.iterations}\n'
|
||||
f'Average time per iteration: {attempts_to_average(bench_attempts, benchmark.iterations)} ms\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
__all__ = [
|
||||
"benchmark_no_aliases",
|
||||
"benchmark_many_aliases",
|
||||
"benchmark_few_aliases",
|
||||
"benchmark_extreme_aliases",
|
||||
"benchmark_very_many_aliases"
|
||||
]
|
||||
|
||||
from argenta import App
|
||||
from argenta.router import Router
|
||||
from argenta.command.models import Command
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ class Benchmark:
|
||||
self.description = description
|
||||
self.iterations = iterations
|
||||
|
||||
def __call__(self) -> float:
|
||||
def run(self) -> float:
|
||||
return self.func()
|
||||
|
||||
@override
|
||||
@@ -84,9 +84,9 @@ class Benchmarks:
|
||||
return decorator
|
||||
else:
|
||||
return decorator(call)
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_benchmarks(cls) -> list[Benchmark]:
|
||||
return cls._benchmarks
|
||||
|
||||
|
||||
benchmark = Benchmarks.register
|
||||
|
||||
+7
-6
@@ -1,22 +1,23 @@
|
||||
__all__ = [
|
||||
"get_time_of_pre_cycle_setup",
|
||||
"attempts_to_average"
|
||||
]
|
||||
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
import time
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
from argenta import App
|
||||
|
||||
|
||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||
"""
|
||||
Public. Return time of pre cycle setup
|
||||
:param app: app instance for testing time of pre cycle setup
|
||||
:return: time of pre cycle setup as float
|
||||
"""
|
||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||
start = time.monotonic()
|
||||
with redirect_stdout(io.StringIO()):
|
||||
app._pre_cycle_setup() # pyright: ignore[reportPrivateUsage]
|
||||
end = time.monotonic()
|
||||
return end - start
|
||||
|
||||
|
||||
def attempts_to_average(bench_attempts: list[float], iterations: int) -> Decimal:
|
||||
return Decimal(sum(bench_attempts) / iterations).quantize(Decimal("0.00001"), rounding=ROUND_HALF_UP)
|
||||
|
||||
Reference in New Issue
Block a user