Skip to content

Commit d6b286b

Browse files
committed
ENH: Add an example of parametrization
1 parent a96a817 commit d6b286b

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

asv.conf.base.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"environment_type": "virtualenv",
88
"matrix": {
99
"req": {
10-
"numpy": ["", null],
10+
"numpy": [""],
1111
},
1212
},
1313
"env_dir": ".asv/env",

benchmarks/benchmarks.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
from asv_samples.benchme import add_arr
1+
import numpy as np
2+
from asv_runner.benchmarks.mark import parameterize, SkipNotImplemented
3+
from asv_samples.benchme import NUMPY_AVAILABLE
24

5+
if not NUMPY_AVAILABLE:
6+
raise SkipNotImplemented("Can't run without NumPy")
37

4-
class TimeSuite:
5-
"""
6-
Benchmark that times various operations, including custom summation of
7-
lists.
8-
"""
8+
@parameterize({"n":[10, 100]})
9+
def time_sort(n):
10+
np.sort(np.random.rand(n))
911

10-
def setup(self):
11-
self.list1 = [i for i in range(500)]
12-
self.list2 = [i for i in range(500, 1000)]
12+
@parameterize({'n': [10, 100], 'func_name': ['range', 'arange']})
13+
def time_ranges_multi(n, func_name):
14+
f = {'range': range, 'arange': np.arange}[func_name]
15+
for i in f(n):
16+
pass
1317

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)
18+
@parameterize({"size": [10, 100, 200]})
19+
class TimeSuiteDecoratorSingle:
20+
def setup(self, size):
21+
self.d = {}
22+
for x in range(size):
23+
self.d[x] = None
24+
25+
def time_keys(self, size):
26+
for key in self.d.keys():
27+
pass
28+
29+
def time_values(self, size):
30+
for value in self.d.values():
31+
pass
32+
33+
@parameterize({'n': [10, 100], 'func_name': ['range', 'arange']})
34+
class TimeSuiteMultiDecorator:
35+
def time_ranges(self, n, func_name):
36+
f = {'range': range, 'arange': np.arange}[func_name]
37+
for i in f(n):
38+
pass

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)