-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tim Paine <[email protected]>
- Loading branch information
Showing
11 changed files
with
203 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"stats.basic.StatsBenchmarkSuite.time_stats": { | ||
"code": "class StatsBenchmarkSuite:\n def time_stats(self, function):\n def g():\n data = csp.curve(typ=np.ndarray, data=self.data)\n value = getattr(csp.stats, function)(data, interval=self.interval, **self.function_args.get(function, {}))\n csp.add_graph_output(\"final_value\", value, tick_count=1)\n \n timer = Timer(\n lambda: csp.run(g, realtime=False, starttime=self.start_date, endtime=timedelta(seconds=self.num_rows))\n )\n elapsed = timer.timeit(1)\n return elapsed\n\n def setup(self, _):\n self.start_date = datetime(2020, 1, 1)\n self.num_rows = 1_000\n self.array_size = 100\n self.test_times = [self.start_date + timedelta(seconds=i) for i in range(self.num_rows)]\n self.random_values = [\n np.random.normal(size=(self.array_size,)) for i in range(self.num_rows)\n ] # 100 element np array\n self.data = list(zip(self.test_times, self.random_values))\n self.interval = 500", | ||
"min_run_count": 2, | ||
"name": "stats.basic.StatsBenchmarkSuite.time_stats", | ||
"number": 0, | ||
"param_names": [ | ||
"function" | ||
], | ||
"params": [ | ||
[ | ||
"'median'", | ||
"'quantile'", | ||
"'rank'" | ||
] | ||
], | ||
"rounds": 2, | ||
"sample_time": 0.01, | ||
"type": "time", | ||
"unit": "seconds", | ||
"version": "f57f3ee288b0805597f9edee91b4d1dddf41046d34fbd46cfbd7135f459e62e3", | ||
"warmup_time": -1 | ||
}, | ||
"version": 2 | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ channels: | |
- conda-forge | ||
- nodefaults | ||
dependencies: | ||
- asv | ||
- bison | ||
- brotli | ||
- build | ||
|
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ channels: | |
- conda-forge | ||
- nodefaults | ||
dependencies: | ||
- asv | ||
- brotli | ||
- build | ||
- bump2version>=1 | ||
|
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 @@ | ||
from .common import * |
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,33 @@ | ||
// https://asv.readthedocs.io/en/v0.6.3/asv.conf.json.html | ||
{ | ||
"version": 1, | ||
"project": "csp", | ||
"project_url": "https://github.com/Point72/csp", | ||
"repo": "../..", | ||
"branches": ["main", "tkp/bm"], | ||
"dvcs": "git", | ||
|
||
"install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"], | ||
"uninstall_command": ["return-code=any python -mpip uninstall -y {project}"], | ||
"build_command": [ | ||
"python -m pip install build", | ||
"python -m build --wheel -o {build_cache_dir} {build_dir}" | ||
], | ||
"environment_type": "virtualenv", | ||
"install_timeout": 600, | ||
"show_commit_url": "http://github.com/point72/csp/commit/", | ||
|
||
"pythons": ["3.11"], | ||
|
||
// "environment_type": "mamba", | ||
// "conda_channels": ["conda-forge"], | ||
// "conda_environment_file": "conda/dev-environment-unix.yml", | ||
|
||
"benchmark_dir": "../../csp/benchmarks", | ||
"env_dir": "../../.asv/env", | ||
"results_dir": "../../ci/benchmarks", | ||
"html_dir": "../../.asv/html", | ||
|
||
"hash_length": 8, | ||
"build_cache_size": 2 | ||
} |
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,63 @@ | ||
from asv_runner.benchmarks import benchmark_types | ||
from asv_runner.benchmarks.mark import SkipNotImplemented | ||
from logging import getLogger | ||
|
||
__all__ = ("ASVBenchmarkHelper",) | ||
|
||
|
||
class ASVBenchmarkHelper: | ||
"""A helper base class to mimic some of what ASV does when running benchmarks, to | ||
test them outside of ASV. | ||
NOTE: should be removed in favor of calling ASV itself from python, if possible. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.log = getLogger(self.__class__.__name__) | ||
|
||
def run_all(self): | ||
# https://asv.readthedocs.io/en/v0.6.3/writing_benchmarks.html#benchmark-types | ||
benchmarks = {} | ||
|
||
for method in dir(self): | ||
for cls in benchmark_types: | ||
if cls.name_regex.match(method): | ||
benchmark_type = cls.__name__.replace("Benchmark", "") | ||
if benchmark_type not in benchmarks: | ||
benchmarks[benchmark_type] = [] | ||
|
||
name = f"{self.__class__.__qualname__}.{method}" | ||
func = getattr(self, method) | ||
benchmarks[benchmark_type].append(cls(name, func, (func, self))) | ||
|
||
def run_benchmark(benchmark): | ||
skip = benchmark.do_setup() | ||
try: | ||
if skip: | ||
return | ||
try: | ||
benchmark.do_run() | ||
except SkipNotImplemented: | ||
pass | ||
finally: | ||
benchmark.do_teardown() | ||
|
||
for type, benchmarks_to_run in benchmarks.items(): | ||
if benchmarks_to_run: | ||
self.log.warn(f"Running benchmarks for {type}") | ||
for benchmark in benchmarks_to_run: | ||
if len(getattr(self, "params", [])): | ||
# TODO: cleaner | ||
param_count = 0 | ||
while param_count < 100: | ||
try: | ||
benchmark.set_param_idx(param_count) | ||
params = benchmark._current_params | ||
self.log.warn(f"[{type}][{benchmark.name}][{'.'.join(str(_) for _ in params)}]") | ||
run_benchmark(benchmark=benchmark) | ||
param_count += 1 | ||
except ValueError: | ||
break | ||
else: | ||
self.log.warn(f"Running [{type}][{benchmark.func.__name__}]") | ||
run_benchmark(benchmark=benchmark) |
Empty file.
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,50 @@ | ||
import numpy as np | ||
from datetime import datetime, timedelta | ||
from timeit import Timer | ||
|
||
import csp | ||
from csp.benchmarks import ASVBenchmarkHelper | ||
|
||
__all__ = ("StatsBenchmarkSuite",) | ||
|
||
|
||
class StatsBenchmarkSuite(ASVBenchmarkHelper): | ||
""" | ||
python -m csp.benchmarks.stats.basic | ||
""" | ||
|
||
params = (("median", "quantile", "rank"),) | ||
param_names = ("function",) | ||
|
||
rounds = 5 | ||
repeat = (100, 200, 60.0) | ||
|
||
function_args = {"quantile": {"quant": 0.95}} | ||
|
||
def setup(self, _): | ||
self.start_date = datetime(2020, 1, 1) | ||
self.num_rows = 1_000 | ||
self.array_size = 100 | ||
self.test_times = [self.start_date + timedelta(seconds=i) for i in range(self.num_rows)] | ||
self.random_values = [ | ||
np.random.normal(size=(self.array_size,)) for i in range(self.num_rows) | ||
] # 100 element np array | ||
self.data = list(zip(self.test_times, self.random_values)) | ||
self.interval = 500 | ||
|
||
def time_stats(self, function): | ||
def g(): | ||
data = csp.curve(typ=np.ndarray, data=self.data) | ||
value = getattr(csp.stats, function)(data, interval=self.interval, **self.function_args.get(function, {})) | ||
csp.add_graph_output("final_value", value, tick_count=1) | ||
|
||
timer = Timer( | ||
lambda: csp.run(g, realtime=False, starttime=self.start_date, endtime=timedelta(seconds=self.num_rows)) | ||
) | ||
elapsed = timer.timeit(1) | ||
return elapsed | ||
|
||
|
||
if __name__ == "__main__": | ||
sbs = StatsBenchmarkSuite() | ||
sbs.run_all() |
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