Skip to content

Commit f201233

Browse files
committed
ENH: Add some skip parameters
1 parent dcf9c3e commit f201233

File tree

2 files changed

+100
-13
lines changed

2 files changed

+100
-13
lines changed

benchmarks/benchmarks.py

+78-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,83 @@
1-
from asv_samples.benchme import add_arr
1+
from asv_runner.benchmarks.mark import (
2+
skip_for_params,
3+
parameterize,
4+
SkipNotImplemented,
5+
skip_benchmark_if,
6+
skip_params_if,
7+
skip_benchmark,
8+
)
9+
import datetime
210

311

412
class TimeSuite:
5-
"""
6-
Benchmark that times various operations, including custom summation of
7-
lists.
8-
"""
13+
params = [100, 200, 300, 400, 500]
14+
param_names = ["size"]
915

16+
def setup(self, size):
17+
self.d = {}
18+
for x in range(size):
19+
self.d[x] = None
20+
21+
@skip_benchmark_if(datetime.datetime.now().hour >= 12)
22+
def time_keys(self, size):
23+
for key in self.d.keys():
24+
pass
25+
26+
@skip_benchmark_if(datetime.datetime.now().hour >= 12)
27+
def time_values(self, size):
28+
for value in self.d.values():
29+
pass
30+
31+
@skip_benchmark_if(datetime.datetime.now().hour >= 12)
32+
def time_range(self, size):
33+
d = self.d
34+
for key in range(size):
35+
d[key]
36+
37+
# Skip benchmarking when size is either 100 or 200 and the current hour is 12 or later.
38+
@skip_params_if([(100,), (200,)], datetime.datetime.now().hour >= 12)
39+
def time_dict_update(self, size):
40+
d = self.d
41+
for i in range(size):
42+
d[i] = i
43+
44+
45+
# Fast because no setup is called
46+
class SimpleFast:
47+
params = [False, True]
48+
param_names = ["ok"]
49+
50+
@skip_for_params([(False,)])
51+
def time_failure(self, ok):
52+
if ok:
53+
x = 34.2**4.2
54+
55+
56+
@parameterize({"ok": [False, True]})
57+
class SimpleSlow:
58+
def time_failure(self, ok):
59+
if ok:
60+
x = 34.2**4.2
61+
else:
62+
raise SkipNotImplemented(f"{ok} is skipped")
63+
64+
65+
@skip_benchmark
66+
class TimeSuiteTwo:
1067
def setup(self):
11-
self.list1 = [i for i in range(500)]
12-
self.list2 = [i for i in range(500, 1000)]
13-
14-
def time_add_arr(self):
15-
"""
16-
Time the add_arr function with two lists of numbers.
17-
"""
18-
add_arr(self.list1, self.list2)
68+
self.d = {}
69+
for x in range(500):
70+
self.d[x] = None
71+
72+
def time_keys(self):
73+
for key in self.d.keys():
74+
pass
75+
76+
def time_values(self):
77+
for value in self.d.values():
78+
pass
79+
80+
def time_range(self):
81+
d = self.d
82+
for key in range(500):
83+
d[key]

pyproject.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = [ "hatch-vcs", "hatchling" ]
4+
5+
[tool.hatch.build.hooks.vcs]
6+
version-file = "_version.py"
7+
8+
[tool.hatch.build]
9+
include = [ "asv_samples/**/*.py", "asv_samples/*.py" ]
10+
11+
[project]
12+
name = "asv_samples"
13+
version = "0.1.0"
14+
description = "A set of asv samples"
15+
authors = [
16+
{name = "Rohit Goswami", email = "[email protected]"},
17+
]
18+
license = {file = "LICENSE"}
19+
readme = "readme.md"
20+
21+
[project.urls]
22+
repository = "https://github.com/HaoZeke/asv_samples"

0 commit comments

Comments
 (0)