Skip to content

Commit d1969cc

Browse files
committed
Setup benchmark suite
Signed-off-by: Tim Paine <[email protected]>
1 parent 323122e commit d1969cc

File tree

9 files changed

+106
-0
lines changed

9 files changed

+106
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ csp/lib/
104104
*.so
105105
*.tsbuildinfo
106106

107+
# Benchmarks
108+
.asv
109+
107110
# Jupyter / Editors
108111
.ipynb_checkpoints
109112
.autoversion

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ dockerps: ## spin up docker compose services for adapter testing
118118
dockerdown: ## spin up docker compose services for adapter testing
119119
$(DOCKER) compose -f ci/$(ADAPTER)/docker-compose.yml down
120120

121+
##############
122+
# BENCHMARKS #
123+
##############
124+
.PHONY: benchmark benchmarks
125+
benchmark: ## run benchmarks
126+
python -m asv run --config csp/benchmarks/asv.conf.jsonc --verbose
127+
128+
121129
###########
122130
# VERSION #
123131
###########

conda/dev-environment-unix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6+
- asv
67
- bison
78
- brotli
89
- build

conda/dev-environment-win.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6+
- asv
67
- brotli
78
- build
89
- bump2version>=1

csp/benchmarks/__init__.py

Whitespace-only changes.

csp/benchmarks/asv.conf.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// https://asv.readthedocs.io/en/v0.6.3/asv.conf.json.html
2+
{
3+
"version": 1,
4+
"project": "csp",
5+
"project_url": "https://github.com/Point72/csp",
6+
"repo": "../..",
7+
"branches": ["main"],
8+
"dvcs": "git",
9+
10+
"install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
11+
"uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
12+
"build_command": [
13+
"python -m pip install build",
14+
"python -m build",
15+
"python -mpip wheel -w {build_cache_dir} {build_dir}"
16+
],
17+
"environment_type": "virtualenv",
18+
"install_timeout": 600,
19+
"show_commit_url": "http://github.com/point72/csp/commit/",
20+
21+
"pythons": ["3.11"],
22+
23+
// "environment_type": "mamba",
24+
// "conda_channels": ["conda-forge"],
25+
// "conda_environment_file": "conda/dev-environment-unix.yml",
26+
27+
"benchmark_dir": "../../csp/benchmarks",
28+
"env_dir": "../../.asv/env",
29+
"results_dir": "../../.asv/results",
30+
"html_dir": "../../.asv/html",
31+
32+
"hash_length": 8,
33+
"build_cache_size": 2
34+
}

csp/benchmarks/stats/__init__.py

Whitespace-only changes.

csp/benchmarks/stats/basic.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import numpy as np
2+
import time
3+
from datetime import datetime, timedelta
4+
5+
import csp
6+
7+
8+
class StatsBenchmarkSuite:
9+
def setup(self):
10+
self.st = datetime(2020, 1, 1)
11+
self.N = 10_000
12+
self.ARRAY_SIZE = 100
13+
self.TEST_TIMES = [self.st + timedelta(seconds=i) for i in range(self.N)]
14+
self.RANDOM_VALUES = [np.random.normal(size=(self.ARRAY_SIZE,)) for i in range(self.N)] # 100 element np array
15+
self.DATA = list(zip(self.TEST_TIMES, self.RANDOM_VALUES))
16+
self.INTERVAL = 1000
17+
self.NUM_SAMPLES = 100
18+
19+
def time_stats_qtl(self):
20+
def g_qtl():
21+
data = csp.curve(typ=np.ndarray, data=self.DATA)
22+
median = csp.stats.median(data, interval=self.INTERVAL)
23+
csp.add_graph_output("final_median", median, tick_count=1)
24+
25+
qtl_times = []
26+
27+
for _ in range(self.NUM_SAMPLES):
28+
start = time.time()
29+
csp.run(g_qtl, starttime=self.st, endtime=timedelta(seconds=self.N))
30+
post_qtl = time.time()
31+
qtl_times.append(post_qtl - start)
32+
33+
avg_med = sum(qtl_times) / self.NUM_SAMPLES
34+
print(
35+
f"Average time in {self.NUM_SAMPLES} tests for median with {self.N=}, {self.ARRAY_SIZE=}, {self.INTERVAL=}: {round(avg_med, 2)} s"
36+
)
37+
return avg_med
38+
39+
def time_stats_rank(self):
40+
def g_rank(self):
41+
data = csp.curve(typ=np.ndarray, data=self.DATA)
42+
rank = csp.stats.rank(data, interval=self.INTERVAL)
43+
csp.add_graph_output("final_rank", rank, tick_count=1)
44+
45+
rank_times = []
46+
47+
for _ in range(self.NUM_SAMPLES):
48+
start = time.time()
49+
csp.run(g_rank, starttime=self.st, endtime=timedelta(seconds=self.stN))
50+
post_rank = time.time()
51+
rank_times.append(post_rank - start)
52+
53+
avg_rank = sum(rank_times) / self.NUM_SAMPLES
54+
print(
55+
f"Average time in {self.NUM_SAMPLES} tests for rank with {self.N=}, {self.ARRAY_SIZE=}, {self.INTERVAL=}: {round(avg_rank, 2)} s"
56+
)
57+
return avg_rank

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ develop = [
8383
"sqlalchemy", # db
8484
"threadpoolctl", # test_random
8585
"tornado", # profiler, perspective, websocket
86+
# benchmarks
87+
"asv",
8688
]
8789
showgraph = [
8890
"graphviz",

0 commit comments

Comments
 (0)