Skip to content

Commit

Permalink
ENH: Add an example of parametrization
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Feb 11, 2024
1 parent 7886e44 commit f19d7f4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion asv.conf.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"environment_type": "conda",
"matrix": {
"req": {
"numpy": ["", null],
"numpy": [""],
},
},
"env_dir": ".asv/env",
Expand Down
48 changes: 34 additions & 14 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
from asv_samples.benchme import add_arr
import numpy as np
from asv_runner.benchmarks.mark import parameterize, SkipNotImplemented
from asv_samples.benchme import NUMPY_AVAILABLE

if not NUMPY_AVAILABLE:
raise SkipNotImplemented("Can't run without NumPy")

class TimeSuite:
"""
Benchmark that times various operations, including custom summation of
lists.
"""
@parameterize({"n":[10, 100]})
def time_sort(n):
np.sort(np.random.rand(n))

def setup(self):
self.list1 = [i for i in range(500)]
self.list2 = [i for i in range(500, 1000)]
@parameterize({'n': [10, 100], 'func_name': ['range', 'arange']})
def time_ranges_multi(n, func_name):
f = {'range': range, 'arange': np.arange}[func_name]
for i in f(n):
pass

def time_add_arr(self):
"""
Time the add_arr function with two lists of numbers.
"""
add_arr(self.list1, self.list2)
@parameterize({"size": [10, 100, 200]})
class TimeSuiteDecoratorSingle:
def setup(self, size):
self.d = {}
for x in range(size):
self.d[x] = None

def time_keys(self, size):
for key in self.d.keys():
pass

def time_values(self, size):
for value in self.d.values():
pass

@parameterize({'n': [10, 100], 'func_name': ['range', 'arange']})
class TimeSuiteMultiDecorator:
def time_ranges(self, n, func_name):
f = {'range': range, 'arange': np.arange}[func_name]
for i in f(n):
pass
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[build-system]
build-backend = "hatchling.build"
requires = [ "hatch-vcs", "hatchling" ]

[tool.hatch.build.hooks.vcs]
version-file = "_version.py"

[tool.hatch.build]
include = [ "asv_samples/**/*.py", "asv_samples/*.py" ]

[project]
name = "asv_samples"
version = "0.1.0"
description = "A set of asv samples"
authors = [
{name = "Rohit Goswami", email = "rgoswami@ieee.org"},
]
license = {file = "LICENSE"}
readme = "readme.md"

[project.urls]
repository = "https://github.com/HaoZeke/asv_samples"

0 comments on commit f19d7f4

Please sign in to comment.