mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
ruff format
This commit is contained in:
@@ -13,8 +13,10 @@ class BenchmarksNotFound(Exception):
|
||||
def __str__(self) -> str:
|
||||
return f"Benchmarks with type '{self.type_}' not found"
|
||||
|
||||
|
||||
class BenchmarksWithSameNameAlreadyExists(Exception):
|
||||
def __init__(self, benchmark_name: str):
|
||||
self.benchmark_name = benchmark_name
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Benchmarks with name '{self.benchmark_name}' already exists"
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
__all__ = [
|
||||
"Benchmark",
|
||||
"Benchmarks",
|
||||
"BenchmarkResult",
|
||||
"BenchmarkGroupResult"
|
||||
]
|
||||
__all__ = ["Benchmark", "Benchmarks", "BenchmarkResult", "BenchmarkGroupResult"]
|
||||
|
||||
import gc
|
||||
import io
|
||||
import statistics
|
||||
import time
|
||||
from contextlib import redirect_stdout
|
||||
from dataclasses import dataclass
|
||||
import time
|
||||
import gc
|
||||
import statistics
|
||||
from typing import Callable, override
|
||||
|
||||
from .exceptions import BenchmarkNotFound, BenchmarksNotFound, BenchmarksWithSameNameAlreadyExists
|
||||
@@ -40,14 +35,7 @@ class BenchmarkGroupResult:
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(
|
||||
self,
|
||||
func: FuncForBenchmark,
|
||||
*,
|
||||
type_: str,
|
||||
name: str,
|
||||
description: str
|
||||
) -> None:
|
||||
def __init__(self, func: FuncForBenchmark, *, type_: str, name: str, description: str) -> None:
|
||||
self.func = func
|
||||
self.type_ = type_
|
||||
self.name = name
|
||||
@@ -78,11 +66,11 @@ class Benchmark:
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
return f'Benchmark<{self.type_=}, {self.name=}, {self.description=}>'
|
||||
return f"Benchmark<{self.type_=}, {self.name=}, {self.description=}>"
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f'benchmark {self.name} with type {self.type_}'
|
||||
return f"benchmark {self.name} with type {self.type_}"
|
||||
|
||||
|
||||
class Benchmarks:
|
||||
@@ -92,16 +80,14 @@ class Benchmarks:
|
||||
self._benchmarks_paired_by_name: dict[str, Benchmark] = {}
|
||||
|
||||
def register(
|
||||
self,
|
||||
type_: str,
|
||||
description: str = ""
|
||||
self, type_: str, description: str = ""
|
||||
) -> Callable[[FuncForBenchmark], FuncForBenchmark]:
|
||||
def decorator(func: FuncForBenchmark) -> FuncForBenchmark:
|
||||
benchmark = Benchmark(
|
||||
func,
|
||||
type_=type_,
|
||||
name=func.__name__,
|
||||
description=description or f'description for {func.__name__} with type {type_}',
|
||||
description=description or f"description for {func.__name__} with type {type_}",
|
||||
)
|
||||
if self._benchmarks_paired_by_name.get(func.__name__):
|
||||
raise BenchmarksWithSameNameAlreadyExists(func.__name__)
|
||||
@@ -110,9 +96,12 @@ class Benchmarks:
|
||||
self._benchmarks.append(benchmark)
|
||||
self._benchmarks_grouped_by_type.setdefault(type_, []).append(benchmark)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
def run_benchmark_by_name(self, name: str, iterations: int = 100, is_gc_disables: bool = False) -> BenchmarkResult:
|
||||
def run_benchmark_by_name(
|
||||
self, name: str, iterations: int = 100, is_gc_disables: bool = False
|
||||
) -> BenchmarkResult:
|
||||
benchmark = self.get_benchmark_by_name(name)
|
||||
if not benchmark:
|
||||
raise BenchmarkNotFound(name)
|
||||
@@ -130,28 +119,34 @@ class Benchmarks:
|
||||
is_gc_disabled=is_gc_disables,
|
||||
avg_time=avg,
|
||||
median_time=median,
|
||||
std_dev=std_dev
|
||||
std_dev=std_dev,
|
||||
)
|
||||
|
||||
def run_benchmarks_by_type(self, type_: str, iterations: int = 100, is_gc_disabled: bool = False) -> BenchmarkGroupResult:
|
||||
def run_benchmarks_by_type(
|
||||
self, type_: str, iterations: int = 100, is_gc_disabled: bool = False
|
||||
) -> BenchmarkGroupResult:
|
||||
benchmarks = self.get_benchmarks_by_type(type_)
|
||||
if not benchmarks:
|
||||
raise BenchmarksNotFound(type_)
|
||||
benchmark_results: list[BenchmarkResult] = []
|
||||
|
||||
for benchmark in benchmarks:
|
||||
benchmark_results.append(self.run_benchmark_by_name(benchmark.name, iterations, is_gc_disabled))
|
||||
benchmark_results.append(
|
||||
self.run_benchmark_by_name(benchmark.name, iterations, is_gc_disabled)
|
||||
)
|
||||
|
||||
return BenchmarkGroupResult(
|
||||
type_=type_,
|
||||
iterations=iterations,
|
||||
is_gc_disabled=is_gc_disabled,
|
||||
benchmark_results=benchmark_results
|
||||
benchmark_results=benchmark_results,
|
||||
)
|
||||
|
||||
def run_benchmarks_grouped_by_type(self, iterations: int = 100, is_gc_disabled: bool = False) -> list[BenchmarkGroupResult]:
|
||||
def run_benchmarks_grouped_by_type(
|
||||
self, iterations: int = 100, is_gc_disabled: bool = False
|
||||
) -> list[BenchmarkGroupResult]:
|
||||
results: list[BenchmarkGroupResult] = []
|
||||
for type_, benchmarks in self._benchmarks_grouped_by_type.items():
|
||||
for type_, _ in self._benchmarks_grouped_by_type.items():
|
||||
results.append(self.run_benchmarks_by_type(type_, iterations, is_gc_disabled))
|
||||
return results
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ __all__ = [
|
||||
"benchmark_command_with_flags",
|
||||
"benchmark_many_commands",
|
||||
"benchmark_command_with_many_flags",
|
||||
"benchmark_extreme_router"
|
||||
"benchmark_extreme_router",
|
||||
]
|
||||
|
||||
from argenta.command.models import Command, InputCommand
|
||||
from argenta.command import Flag, Flags
|
||||
from argenta.command.models import Command, InputCommand
|
||||
from argenta.response import Response
|
||||
from argenta.router import Router
|
||||
|
||||
@@ -18,11 +18,11 @@ from .entity import benchmarks
|
||||
def benchmark_simple_command() -> None:
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('test'))
|
||||
@router.command(Command("test"))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
input_cmd = InputCommand.parse('test')
|
||||
input_cmd = InputCommand.parse("test")
|
||||
router.finds_appropriate_handler(input_cmd)
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ def benchmark_simple_command() -> None:
|
||||
def benchmark_command_with_flags() -> None:
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('test', flags=Flags([Flag('a'), Flag('b'), Flag('c')])))
|
||||
@router.command(Command("test", flags=Flags([Flag("a"), Flag("b"), Flag("c")])))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
input_cmd = InputCommand.parse('test -a -b -c')
|
||||
input_cmd = InputCommand.parse("test -a -b -c")
|
||||
router.finds_appropriate_handler(input_cmd)
|
||||
|
||||
|
||||
@@ -43,38 +43,43 @@ def benchmark_many_commands() -> None:
|
||||
router = Router()
|
||||
|
||||
for i in range(50):
|
||||
@router.command(Command(f'cmd{i}'))
|
||||
|
||||
@router.command(Command(f"cmd{i}"))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
input_cmd = InputCommand.parse('cmd25')
|
||||
input_cmd = InputCommand.parse("cmd25")
|
||||
router.finds_appropriate_handler(input_cmd)
|
||||
|
||||
|
||||
@benchmarks.register(type_="finds_appropriate_handler", description="Command with many flags (20 flags)")
|
||||
@benchmarks.register(
|
||||
type_="finds_appropriate_handler", description="Command with many flags (20 flags)"
|
||||
)
|
||||
def benchmark_command_with_many_flags() -> None:
|
||||
router = Router()
|
||||
|
||||
flags = Flags([Flag(f'flag{i}') for i in range(20)])
|
||||
flags = Flags([Flag(f"flag{i}") for i in range(20)])
|
||||
|
||||
@router.command(Command('test', flags=flags))
|
||||
@router.command(Command("test", flags=flags))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
input_cmd = InputCommand.parse('test ' + ' '.join(f'-flag{i}' for i in range(10)))
|
||||
input_cmd = InputCommand.parse("test " + " ".join(f"-flag{i}" for i in range(10)))
|
||||
router.finds_appropriate_handler(input_cmd)
|
||||
|
||||
|
||||
@benchmarks.register(type_="finds_appropriate_handler", description="Extreme (100 commands, 10 flags each)")
|
||||
@benchmarks.register(
|
||||
type_="finds_appropriate_handler", description="Extreme (100 commands, 10 flags each)"
|
||||
)
|
||||
def benchmark_extreme_router() -> None:
|
||||
router = Router()
|
||||
|
||||
for i in range(100):
|
||||
flags = Flags([Flag(f'f{i}_{j}') for j in range(10)])
|
||||
flags = Flags([Flag(f"f{i}_{j}") for j in range(10)])
|
||||
|
||||
@router.command(Command(f'cmd{i}', flags=flags))
|
||||
@router.command(Command(f"cmd{i}", flags=flags))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
input_cmd = InputCommand.parse('cmd50 -f50_0 -f50_1 -f50_2')
|
||||
input_cmd = InputCommand.parse("cmd50 -f50_0 -f50_1 -f50_2")
|
||||
router.finds_appropriate_handler(input_cmd)
|
||||
|
||||
@@ -7,7 +7,7 @@ __all__ = [
|
||||
"benchmark_validate_regex_complex",
|
||||
"benchmark_validate_multiple_flags_10",
|
||||
"benchmark_validate_multiple_flags_50",
|
||||
"benchmark_validate_extreme_100_flags"
|
||||
"benchmark_validate_extreme_100_flags",
|
||||
]
|
||||
|
||||
import re
|
||||
@@ -58,45 +58,29 @@ def benchmark_validate_regex_complex() -> None:
|
||||
|
||||
@benchmarks.register(type_="flag_validation", description="Multiple flags validation (10 flags)")
|
||||
def benchmark_validate_multiple_flags_10() -> None:
|
||||
flags = [
|
||||
Flag(f"flag{i}", possible_values=PossibleValues.ALL)
|
||||
for i in range(10)
|
||||
]
|
||||
input_flags = [
|
||||
InputFlag(f"flag{i}", input_value=f"value{i}")
|
||||
for i in range(10)
|
||||
]
|
||||
|
||||
flags = [Flag(f"flag{i}", possible_values=PossibleValues.ALL) for i in range(10)]
|
||||
input_flags = [InputFlag(f"flag{i}", input_value=f"value{i}") for i in range(10)]
|
||||
|
||||
for flag, input_flag in zip(flags, input_flags):
|
||||
flag.validate_input_flag_value(input_flag.input_value)
|
||||
|
||||
|
||||
@benchmarks.register(type_="flag_validation", description="Multiple flags validation (50 flags)")
|
||||
def benchmark_validate_multiple_flags_50() -> None:
|
||||
flags = [
|
||||
Flag(f"flag{i}", possible_values=PossibleValues.ALL)
|
||||
for i in range(50)
|
||||
]
|
||||
input_flags = [
|
||||
InputFlag(f"flag{i}", input_value=f"value{i}")
|
||||
for i in range(50)
|
||||
]
|
||||
|
||||
flags = [Flag(f"flag{i}", possible_values=PossibleValues.ALL) for i in range(50)]
|
||||
input_flags = [InputFlag(f"flag{i}", input_value=f"value{i}") for i in range(50)]
|
||||
|
||||
for flag, input_flag in zip(flags, input_flags):
|
||||
flag.validate_input_flag_value(input_flag.input_value)
|
||||
|
||||
|
||||
@benchmarks.register(type_="flag_validation", description="Extreme (100 flags with regex validation)")
|
||||
@benchmarks.register(
|
||||
type_="flag_validation", description="Extreme (100 flags with regex validation)"
|
||||
)
|
||||
def benchmark_validate_extreme_100_flags() -> None:
|
||||
pattern = re.compile(r"^[a-zA-Z0-9_-]+$")
|
||||
flags = [
|
||||
Flag(f"flag{i}", possible_values=pattern)
|
||||
for i in range(100)
|
||||
]
|
||||
input_flags = [
|
||||
InputFlag(f"flag{i}", input_value=f"valid_value_{i}")
|
||||
for i in range(100)
|
||||
]
|
||||
|
||||
flags = [Flag(f"flag{i}", possible_values=pattern) for i in range(100)]
|
||||
input_flags = [InputFlag(f"flag{i}", input_value=f"valid_value_{i}") for i in range(100)]
|
||||
|
||||
for flag, input_flag in zip(flags, input_flags):
|
||||
flag.validate_input_flag_value(input_flag.input_value)
|
||||
|
||||
@@ -5,7 +5,7 @@ __all__ = [
|
||||
"benchmark_command_with_mixed_prefixes",
|
||||
"benchmark_command_with_long_values",
|
||||
"benchmark_command_with_quoted_values",
|
||||
"benchmark_extreme_many_flags"
|
||||
"benchmark_extreme_many_flags",
|
||||
]
|
||||
|
||||
from argenta.command.models import InputCommand
|
||||
@@ -23,12 +23,16 @@ def benchmark_command_with_few_flags() -> None:
|
||||
InputCommand.parse("start -a -b -c")
|
||||
|
||||
|
||||
@benchmarks.register(type_="input_command_parse", description="Command with flags and values (5 flags)")
|
||||
@benchmarks.register(
|
||||
type_="input_command_parse", description="Command with flags and values (5 flags)"
|
||||
)
|
||||
def benchmark_command_with_flags_and_values() -> None:
|
||||
InputCommand.parse("start --host localhost --port 8080 --debug --verbose -c config.json")
|
||||
|
||||
|
||||
@benchmarks.register(type_="input_command_parse", description="Command with mixed prefixes (-, --, ---)")
|
||||
@benchmarks.register(
|
||||
type_="input_command_parse", description="Command with mixed prefixes (-, --, ---)"
|
||||
)
|
||||
def benchmark_command_with_mixed_prefixes() -> None:
|
||||
InputCommand.parse("cmd -a --bb ---ccc -d value --ee value2 ---fff value3")
|
||||
|
||||
@@ -40,7 +44,9 @@ def benchmark_command_with_long_values() -> None:
|
||||
InputCommand.parse(cmd)
|
||||
|
||||
|
||||
@benchmarks.register(type_="input_command_parse", description="Command with quoted values (5 flags)")
|
||||
@benchmarks.register(
|
||||
type_="input_command_parse", description="Command with quoted values (5 flags)"
|
||||
)
|
||||
def benchmark_command_with_quoted_values() -> None:
|
||||
InputCommand.parse("cmd --text 'hello world' --path '/usr/local/bin' --msg \"test message\"")
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ __all__ = [
|
||||
"benchmark_many_commands_most_similar",
|
||||
"benchmark_many_aliases",
|
||||
"benchmark_partial_match",
|
||||
"benchmark_extreme_commands"
|
||||
"benchmark_extreme_commands",
|
||||
]
|
||||
|
||||
from argenta import App
|
||||
@@ -19,9 +19,11 @@ def setup_app_with_commands(command_count: int, aliases_per_command: int = 0) ->
|
||||
router = Router()
|
||||
|
||||
for i in range(command_count):
|
||||
aliases = {f'alias{i}_{j}' for j in range(aliases_per_command)} if aliases_per_command else set()
|
||||
aliases = (
|
||||
{f"alias{i}_{j}" for j in range(aliases_per_command)} if aliases_per_command else set()
|
||||
)
|
||||
|
||||
@router.command(Command(f'command{i}', aliases=aliases))
|
||||
@router.command(Command(f"command{i}", aliases=aliases))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@@ -29,31 +31,41 @@ def setup_app_with_commands(command_count: int, aliases_per_command: int = 0) ->
|
||||
return app
|
||||
|
||||
|
||||
@benchmarks.register(type_="most_similar_command", description="Few commands (10 commands, no match)")
|
||||
@benchmarks.register(
|
||||
type_="most_similar_command", description="Few commands (10 commands, no match)"
|
||||
)
|
||||
def benchmark_few_commands() -> None:
|
||||
app = setup_app_with_commands(10)
|
||||
app._most_similar_command("unknown")
|
||||
|
||||
|
||||
@benchmarks.register(type_="most_similar_command", description="Many commands (50 commands, no match)")
|
||||
@benchmarks.register(
|
||||
type_="most_similar_command", description="Many commands (50 commands, no match)"
|
||||
)
|
||||
def benchmark_many_commands_most_similar() -> None:
|
||||
app = setup_app_with_commands(50)
|
||||
app._most_similar_command("unknown")
|
||||
|
||||
|
||||
@benchmarks.register(type_="most_similar_command", description="Many aliases (20 commands, 10 aliases each)")
|
||||
@benchmarks.register(
|
||||
type_="most_similar_command", description="Many aliases (20 commands, 10 aliases each)"
|
||||
)
|
||||
def benchmark_many_aliases() -> None:
|
||||
app = setup_app_with_commands(20, aliases_per_command=10)
|
||||
app._most_similar_command("unknown")
|
||||
|
||||
|
||||
@benchmarks.register(type_="most_similar_command", description="Partial match (50 commands, prefix match)")
|
||||
@benchmarks.register(
|
||||
type_="most_similar_command", description="Partial match (50 commands, prefix match)"
|
||||
)
|
||||
def benchmark_partial_match() -> None:
|
||||
app = setup_app_with_commands(50)
|
||||
app._most_similar_command("comm")
|
||||
|
||||
|
||||
@benchmarks.register(type_="most_similar_command", description="Extreme (100 commands, 20 aliases each)")
|
||||
@benchmarks.register(
|
||||
type_="most_similar_command", description="Extreme (100 commands, 20 aliases each)"
|
||||
)
|
||||
def benchmark_extreme_commands() -> None:
|
||||
app = setup_app_with_commands(100, aliases_per_command=20)
|
||||
app._most_similar_command("comm")
|
||||
|
||||
@@ -3,7 +3,7 @@ __all__ = [
|
||||
"benchmark_with_many_aliases",
|
||||
"benchmark_few_aliases",
|
||||
"benchmark_extreme_aliases",
|
||||
"benchmark_very_many_aliases"
|
||||
"benchmark_very_many_aliases",
|
||||
]
|
||||
|
||||
from argenta import App
|
||||
@@ -19,16 +19,16 @@ def benchmark_no_aliases() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('command1'))
|
||||
def handler1(_res: Response) -> None:
|
||||
@router.command(Command("command1"))
|
||||
def handler1(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command2'))
|
||||
def handler2(_res: Response) -> None:
|
||||
@router.command(Command("command2"))
|
||||
def handler2(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command3'))
|
||||
def handler3(_res: Response) -> None:
|
||||
@router.command(Command("command3"))
|
||||
def handler3(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
app.include_router(router)
|
||||
@@ -40,16 +40,16 @@ def benchmark_few_aliases() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('command1', aliases={'c1', 'cmd1'}))
|
||||
def handler1(_res: Response) -> None:
|
||||
@router.command(Command("command1", aliases={"c1", "cmd1"}))
|
||||
def handler1(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command2', aliases={'c2', 'cmd2'}))
|
||||
def handler2(_res: Response) -> None:
|
||||
@router.command(Command("command2", aliases={"c2", "cmd2"}))
|
||||
def handler2(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command3', aliases={'c3', 'cmd3'}))
|
||||
def handler3(_res: Response) -> None:
|
||||
@router.command(Command("command3", aliases={"c3", "cmd3"}))
|
||||
def handler3(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
app.include_router(router)
|
||||
@@ -61,16 +61,16 @@ def benchmark_with_many_aliases() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('command1', aliases={'c1', 'cmd1', 'com1', 'first', 'one'}))
|
||||
def handler1(_res: Response) -> None:
|
||||
@router.command(Command("command1", aliases={"c1", "cmd1", "com1", "first", "one"}))
|
||||
def handler1(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command2', aliases={'c2', 'cmd2', 'com2', 'second', 'two'}))
|
||||
def handler2(_res: Response) -> None:
|
||||
@router.command(Command("command2", aliases={"c2", "cmd2", "com2", "second", "two"}))
|
||||
def handler2(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command3', aliases={'c3', 'cmd3', 'com3', 'third', 'three'}))
|
||||
def handler3(_res: Response) -> None:
|
||||
@router.command(Command("command3", aliases={"c3", "cmd3", "com3", "third", "three"}))
|
||||
def handler3(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
app.include_router(router)
|
||||
@@ -82,16 +82,16 @@ def benchmark_very_many_aliases() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('command1', aliases={f'alias1_{i}' for i in range(20)}))
|
||||
def handler1(_res: Response) -> None:
|
||||
@router.command(Command("command1", aliases={f"alias1_{i}" for i in range(20)}))
|
||||
def handler1(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command2', aliases={f'alias2_{i}' for i in range(20)}))
|
||||
def handler2(_res: Response) -> None:
|
||||
@router.command(Command("command2", aliases={f"alias2_{i}" for i in range(20)}))
|
||||
def handler2(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command3', aliases={f'alias3_{i}' for i in range(20)}))
|
||||
def handler3(_res: Response) -> None:
|
||||
@router.command(Command("command3", aliases={f"alias3_{i}" for i in range(20)}))
|
||||
def handler3(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
app.include_router(router)
|
||||
@@ -103,16 +103,16 @@ def benchmark_extreme_aliases() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('command1', aliases={f'alias1_{i}' for i in range(100)}))
|
||||
def handler1(_res: Response) -> None:
|
||||
@router.command(Command("command1", aliases={f"alias1_{i}" for i in range(100)}))
|
||||
def handler1(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command2', aliases={f'alias2_{i}' for i in range(100)}))
|
||||
def handler2(_res: Response) -> None:
|
||||
@router.command(Command("command2", aliases={f"alias2_{i}" for i in range(100)}))
|
||||
def handler2(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@router.command(Command('command3', aliases={f'alias3_{i}' for i in range(100)}))
|
||||
def handler3(_res: Response) -> None:
|
||||
@router.command(Command("command3", aliases={f"alias3_{i}" for i in range(100)}))
|
||||
def handler3(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
app.include_router(router)
|
||||
|
||||
@@ -3,7 +3,7 @@ __all__ = [
|
||||
"benchmark_many_routers",
|
||||
"benchmark_many_commands_per_router",
|
||||
"benchmark_many_aliases_per_command",
|
||||
"benchmark_extreme_routers"
|
||||
"benchmark_extreme_routers",
|
||||
]
|
||||
|
||||
from argenta import App
|
||||
@@ -14,14 +14,17 @@ from argenta.router import Router
|
||||
from .entity import benchmarks
|
||||
|
||||
|
||||
@benchmarks.register(type_="validate_routers_for_collisions", description="With few routers (3 routers, 1 command each)")
|
||||
@benchmarks.register(
|
||||
type_="validate_routers_for_collisions",
|
||||
description="With few routers (3 routers, 1 command each)",
|
||||
)
|
||||
def benchmark_few_routers() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
|
||||
for i in range(3):
|
||||
router = Router()
|
||||
|
||||
@router.command(Command(f'cmd{i}'))
|
||||
@router.command(Command(f"cmd{i}"))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@@ -31,14 +34,17 @@ def benchmark_few_routers() -> None:
|
||||
app._validate_routers_for_collisions()
|
||||
|
||||
|
||||
@benchmarks.register(type_="validate_routers_for_collisions", description="With many routers (10 routers, 1 command each)")
|
||||
@benchmarks.register(
|
||||
type_="validate_routers_for_collisions",
|
||||
description="With many routers (10 routers, 1 command each)",
|
||||
)
|
||||
def benchmark_many_routers() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
|
||||
for i in range(10):
|
||||
router = Router()
|
||||
|
||||
@router.command(Command(f'cmd{i}'))
|
||||
@router.command(Command(f"cmd{i}"))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@@ -48,7 +54,10 @@ def benchmark_many_routers() -> None:
|
||||
app._validate_routers_for_collisions()
|
||||
|
||||
|
||||
@benchmarks.register(type_="validate_routers_for_collisions", description="With many commands per router (3 routers, 10 commands each)")
|
||||
@benchmarks.register(
|
||||
type_="validate_routers_for_collisions",
|
||||
description="With many commands per router (3 routers, 10 commands each)",
|
||||
)
|
||||
def benchmark_many_commands_per_router() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
|
||||
@@ -56,7 +65,8 @@ def benchmark_many_commands_per_router() -> None:
|
||||
router = Router()
|
||||
|
||||
for j in range(10):
|
||||
@router.command(Command(f'cmd{i}_{j}'))
|
||||
|
||||
@router.command(Command(f"cmd{i}_{j}"))
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@@ -66,7 +76,10 @@ def benchmark_many_commands_per_router() -> None:
|
||||
app._validate_routers_for_collisions()
|
||||
|
||||
|
||||
@benchmarks.register(type_="validate_routers_for_collisions", description="With many aliases (3 routers, 5 commands, 10 aliases each)")
|
||||
@benchmarks.register(
|
||||
type_="validate_routers_for_collisions",
|
||||
description="With many aliases (3 routers, 5 commands, 10 aliases each)",
|
||||
)
|
||||
def benchmark_many_aliases_per_command() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
|
||||
@@ -74,7 +87,10 @@ def benchmark_many_aliases_per_command() -> None:
|
||||
router = Router()
|
||||
|
||||
for j in range(5):
|
||||
@router.command(Command(f'cmd{i}_{j}', aliases={f'alias{i}_{j}_{k}' for k in range(10)}))
|
||||
|
||||
@router.command(
|
||||
Command(f"cmd{i}_{j}", aliases={f"alias{i}_{j}_{k}" for k in range(10)})
|
||||
)
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
@@ -84,7 +100,10 @@ def benchmark_many_aliases_per_command() -> None:
|
||||
app._validate_routers_for_collisions()
|
||||
|
||||
|
||||
@benchmarks.register(type_="validate_routers_for_collisions", description="Extreme (20 routers, 10 commands, 20 aliases each)")
|
||||
@benchmarks.register(
|
||||
type_="validate_routers_for_collisions",
|
||||
description="Extreme (20 routers, 10 commands, 20 aliases each)",
|
||||
)
|
||||
def benchmark_extreme_routers() -> None:
|
||||
app = App(override_system_messages=True)
|
||||
|
||||
@@ -92,7 +111,10 @@ def benchmark_extreme_routers() -> None:
|
||||
router = Router()
|
||||
|
||||
for j in range(10):
|
||||
@router.command(Command(f'cmd{i}_{j}', aliases={f'alias{i}_{j}_{k}' for k in range(20)}))
|
||||
|
||||
@router.command(
|
||||
Command(f"cmd{i}_{j}", aliases={f"alias{i}_{j}_{k}" for k in range(20)})
|
||||
)
|
||||
def handler(_res: Response) -> None:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user