-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add benchmarks * docs: add to readme
- Loading branch information
1 parent
9e07bb1
commit f220cd2
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
import in_n_out as ino | ||
|
||
if all(x not in {"--codspeed", "--benchmark", "tests/test_bench.py"} for x in sys.argv): | ||
pytest.skip("use --benchmark to run benchmark", allow_module_level=True) | ||
|
||
|
||
def some_func(x: int, y: str) -> tuple[int, str]: | ||
return x, y | ||
|
||
|
||
def returns_str(x: int, y: str) -> str: | ||
return str(x) + y | ||
|
||
|
||
def test_time_to_inject(benchmark: Callable) -> None: | ||
benchmark(ino.inject, some_func) | ||
|
||
|
||
def test_time_run_injected_no_injections(benchmark: Callable) -> None: | ||
injected = ino.inject(some_func) | ||
benchmark(injected, 1, "a") | ||
|
||
|
||
def test_time_run_injected_2_injections(benchmark: Callable) -> None: | ||
injected = ino.inject(some_func) | ||
with ino.register(providers=[(lambda: 1, int), (lambda: "a", str)]): | ||
benchmark(injected) | ||
|
||
|
||
def test_time_run_process(benchmark: Callable) -> None: | ||
injected = ino.inject_processors(returns_str) | ||
with ino.register(processors=[(lambda x: print(x), str)]): | ||
benchmark(injected, 1, "hi") | ||
|
||
|
||
def test_time_run_inject_and_process(benchmark: Callable) -> None: | ||
injected = ino.inject(returns_str, processors=True) | ||
with ino.register( | ||
providers=[(lambda: "a", str)], processors=[(lambda x: ..., str)] | ||
): | ||
benchmark(injected, 1) |