mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
benchs
This commit is contained in:
+21
-8
@@ -1,7 +1,10 @@
|
|||||||
from concurrent.futures import ProcessPoolExecutor
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from rich import Console
|
from rich.console import Console
|
||||||
|
from rich.table import Table
|
||||||
|
from rich.panel import Panel
|
||||||
|
from rich.text import Text
|
||||||
|
|
||||||
from metrics.utils import run_benchmark, BenchmarkResult
|
from metrics.utils import run_benchmark, BenchmarkResult
|
||||||
from .registry import Benchmarks, Benchmark
|
from .registry import Benchmarks, Benchmark
|
||||||
@@ -21,15 +24,25 @@ def main():
|
|||||||
type_paired_benchmarks.setdefault(result.type_, []).append(result)
|
type_paired_benchmarks.setdefault(result.type_, []).append(result)
|
||||||
|
|
||||||
for type_, benchmarks in type_paired_benchmarks.items():
|
for type_, benchmarks in type_paired_benchmarks.items():
|
||||||
console.print('\n' + ('='*(len(type_)+14)))
|
header_text = Text(f"TYPE: {type_.upper()}", style="bold magenta")
|
||||||
console.print(f' TYPE: {type_.upper()}')
|
console.print(Panel(header_text, expand=False, border_style="magenta"))
|
||||||
console.print('='*(len(type_)+14) + '\n')
|
|
||||||
|
table = Table(show_header=True, header_style="bold cyan", border_style="blue", show_lines=True)
|
||||||
|
table.add_column("Name", style="green")
|
||||||
|
table.add_column("Description", style="dim")
|
||||||
|
table.add_column("Iterations", justify="right")
|
||||||
|
table.add_column("Avg Time (ms)", justify="right", style="bold yellow")
|
||||||
|
|
||||||
for benchmark in benchmarks:
|
for benchmark in benchmarks:
|
||||||
console.print(f'Name: {benchmark.name}\n'
|
table.add_row(
|
||||||
f'Description: {benchmark.description}\n'
|
benchmark.name,
|
||||||
f'Iterations: {benchmark.iterations}\n'
|
benchmark.description,
|
||||||
f'Average time per iteration: {benchmark.avg_time} ms\n')
|
str(benchmark.iterations),
|
||||||
|
str(benchmark.avg_time)
|
||||||
|
)
|
||||||
|
|
||||||
|
console.print(table)
|
||||||
|
console.print()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+4
-4
@@ -16,15 +16,15 @@ from metrics.registry import Benchmark
|
|||||||
|
|
||||||
|
|
||||||
def get_time_of_pre_cycle_setup(app: App) -> float:
|
def get_time_of_pre_cycle_setup(app: App) -> float:
|
||||||
start = time.monotonic()
|
start = time.perf_counter()
|
||||||
with redirect_stdout(io.StringIO()):
|
with redirect_stdout(io.StringIO()):
|
||||||
app._pre_cycle_setup() # pyright: ignore[reportPrivateUsage]
|
app._pre_cycle_setup() # pyright: ignore[reportPrivateUsage]
|
||||||
end = time.monotonic()
|
end = time.perf_counter()
|
||||||
return end - start
|
return (end - start) * 1000 # as milliseconds
|
||||||
|
|
||||||
|
|
||||||
def attempts_to_average(bench_attempts: list[float], iterations: int) -> Decimal:
|
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)
|
return Decimal(sum(bench_attempts) / iterations).quantize(Decimal("0.0001"), rounding=ROUND_HALF_UP)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user