Skip to content

Commit 1161fbe

Browse files
authored
Merge pull request #81 from numpy/bench/initial-asv-setup
BENCH: Initial asv setup
2 parents 0ea8227 + 0a80458 commit 1161fbe

File tree

4 files changed

+236
-0
lines changed

4 files changed

+236
-0
lines changed

asv.conf.json

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
{
2+
// The version of the config file format. Do not change, unless
3+
// you know what you are doing.
4+
"version": 1,
5+
6+
// The name of the project being benchmarked
7+
"project": "NumPy-Financial",
8+
9+
// The project's homepage
10+
"project_url": "https://numpy.org/numpy-financial//",
11+
12+
// The URL or local path of the source code repository for the
13+
// project being benchmarked
14+
"repo": ".",
15+
16+
// The Python project's subdirectory in your repo. If missing or
17+
// the empty string, the project is assumed to be located at the root
18+
// of the repository.
19+
// "repo_subdir": "",
20+
21+
// Customizable commands for building the project.
22+
// See asv.conf.json documentation.
23+
// To build the package using pyproject.toml (PEP518), uncomment the following lines
24+
"build_command": [
25+
"python -m pip install build",
26+
"python -m build",
27+
"PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
28+
],
29+
// To build the package using setuptools and a setup.py file, uncomment the following lines
30+
// "build_command": [
31+
// "python setup.py build",
32+
// "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
33+
// ],
34+
35+
// Customizable commands for installing and uninstalling the project.
36+
// See asv.conf.json documentation.
37+
// "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
38+
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
39+
40+
// List of branches to benchmark. If not provided, defaults to "master"
41+
// (for git) or "default" (for mercurial).
42+
"branches": ["main"],
43+
44+
// The DVCS being used. If not set, it will be automatically
45+
// determined from "repo" by looking at the protocol in the URL
46+
// (if remote), or by looking for special directories, such as
47+
// ".git" (if local).
48+
"dvcs": "git",
49+
50+
// The tool to use to create environments. May be "conda",
51+
// "virtualenv", "mamba" (above 3.8)
52+
// or other value depending on the plugins in use.
53+
// If missing or the empty string, the tool will be automatically
54+
// determined by looking for tools on the PATH environment
55+
// variable.
56+
"environment_type": "virtualenv",
57+
58+
// timeout in seconds for installing any dependencies in environment
59+
// defaults to 10 min
60+
//"install_timeout": 600,
61+
62+
// the base URL to show a commit for the project.
63+
// "show_commit_url": "http://github.com/owner/project/commit/",
64+
65+
// The Pythons you'd like to test against. If not provided, defaults
66+
// to the current version of Python used to run `asv`.
67+
// "pythons": ["2.7", "3.8"],
68+
69+
// The list of conda channel names to be searched for benchmark
70+
// dependency packages in the specified order
71+
// "conda_channels": ["conda-forge", "defaults"],
72+
73+
// A conda environment file that is used for environment creation.
74+
// "conda_environment_file": "environment.yml",
75+
76+
// The matrix of dependencies to test. Each key of the "req"
77+
// requirements dictionary is the name of a package (in PyPI) and
78+
// the values are version numbers. An empty list or empty string
79+
// indicates to just test against the default (latest)
80+
// version. null indicates that the package is to not be
81+
// installed. If the package to be tested is only available from
82+
// PyPi, and the 'environment_type' is conda, then you can preface
83+
// the package name by 'pip+', and the package will be installed
84+
// via pip (with all the conda available packages installed first,
85+
// followed by the pip installed packages).
86+
//
87+
// The ``@env`` and ``@env_nobuild`` keys contain the matrix of
88+
// environment variables to pass to build and benchmark commands.
89+
// An environment will be created for every combination of the
90+
// cartesian product of the "@env" variables in this matrix.
91+
// Variables in "@env_nobuild" will be passed to every environment
92+
// during the benchmark phase, but will not trigger creation of
93+
// new environments. A value of ``null`` means that the variable
94+
// will not be set for the current combination.
95+
//
96+
// "matrix": {
97+
// "req": {
98+
// "numpy": ["1.6", "1.7"],
99+
// "six": ["", null], // test with and without six installed
100+
// "pip+emcee": [""] // emcee is only available for install with pip.
101+
// },
102+
// "env": {"ENV_VAR_1": ["val1", "val2"]},
103+
// "env_nobuild": {"ENV_VAR_2": ["val3", null]},
104+
// },
105+
106+
// Combinations of libraries/python versions can be excluded/included
107+
// from the set to test. Each entry is a dictionary containing additional
108+
// key-value pairs to include/exclude.
109+
//
110+
// An exclude entry excludes entries where all values match. The
111+
// values are regexps that should match the whole string.
112+
//
113+
// An include entry adds an environment. Only the packages listed
114+
// are installed. The 'python' key is required. The exclude rules
115+
// do not apply to includes.
116+
//
117+
// In addition to package names, the following keys are available:
118+
//
119+
// - python
120+
// Python version, as in the *pythons* variable above.
121+
// - environment_type
122+
// Environment type, as above.
123+
// - sys_platform
124+
// Platform, as in sys.platform. Possible values for the common
125+
// cases: 'linux2', 'win32', 'cygwin', 'darwin'.
126+
// - req
127+
// Required packages
128+
// - env
129+
// Environment variables
130+
// - env_nobuild
131+
// Non-build environment variables
132+
//
133+
// "exclude": [
134+
// {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
135+
// {"environment_type": "conda", "req": {"six": null}}, // don't run without six on conda
136+
// {"env": {"ENV_VAR_1": "val2"}}, // skip val2 for ENV_VAR_1
137+
// ],
138+
//
139+
// "include": [
140+
// // additional env for python2.7
141+
// {"python": "2.7", "req": {"numpy": "1.8"}, "env_nobuild": {"FOO": "123"}},
142+
// // additional env if run on windows+conda
143+
// {"platform": "win32", "environment_type": "conda", "python": "2.7", "req": {"libpython": ""}},
144+
// ],
145+
146+
// The directory (relative to the current directory) that benchmarks are
147+
// stored in. If not provided, defaults to "benchmarks"
148+
// "benchmark_dir": "benchmarks",
149+
150+
// The directory (relative to the current directory) to cache the Python
151+
// environments in. If not provided, defaults to "env"
152+
"env_dir": ".asv/env",
153+
154+
// The directory (relative to the current directory) that raw benchmark
155+
// results are stored in. If not provided, defaults to "results".
156+
"results_dir": ".asv/results",
157+
158+
// The directory (relative to the current directory) that the html tree
159+
// should be written to. If not provided, defaults to "html".
160+
"html_dir": ".asv/html",
161+
162+
// The number of characters to retain in the commit hashes.
163+
// "hash_length": 8,
164+
165+
// `asv` will cache results of the recent builds in each
166+
// environment, making them faster to install next time. This is
167+
// the number of builds to keep, per environment.
168+
// "build_cache_size": 2,
169+
170+
// The commits after which the regression search in `asv publish`
171+
// should start looking for regressions. Dictionary whose keys are
172+
// regexps matching to benchmark names, and values corresponding to
173+
// the commit (exclusive) after which to start looking for
174+
// regressions. The default is to start from the first commit
175+
// with results. If the commit is `null`, regression detection is
176+
// skipped for the matching benchmark.
177+
//
178+
// "regressions_first_commits": {
179+
// "some_benchmark": "352cdf", // Consider regressions only after this commit
180+
// "another_benchmark": null, // Skip regression detection altogether
181+
// },
182+
183+
// The thresholds for relative change in results, after which `asv
184+
// publish` starts reporting regressions. Dictionary of the same
185+
// form as in ``regressions_first_commits``, with values
186+
// indicating the thresholds. If multiple entries match, the
187+
// maximum is taken. If no entry matches, the default is 5%.
188+
//
189+
// "regressions_thresholds": {
190+
// "some_benchmark": 0.01, // Threshold of 1%
191+
// "another_benchmark": 0.5, // Threshold of 50%
192+
// },
193+
}

benchmarks/__init__.py

Whitespace-only changes.

benchmarks/benchmarks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
import numpy_financial as npf
3+
4+
5+
class Npv1DCashflow:
6+
7+
param_names = ["cashflow_length"]
8+
params = [
9+
(1, 10, 100, 1000),
10+
]
11+
12+
def __init__(self):
13+
self.cashflows = None
14+
15+
def setup(self, cashflow_length):
16+
rng = np.random.default_rng(0)
17+
self.cashflows = rng.standard_normal(cashflow_length)
18+
19+
def time_1d_cashflow(self, cashflow_length):
20+
npf.npv(0.08, self.cashflows)
21+
22+
23+
class Npv2DCashflows:
24+
25+
param_names = ["n_cashflows", "cashflow_lengths"]
26+
params = [
27+
(1, 10, 100, 1000),
28+
(1, 10, 100, 1000),
29+
]
30+
31+
def __init__(self):
32+
self.cashflows = None
33+
34+
def setup(self, n_cashflows, cashflow_lengths):
35+
rng = np.random.default_rng(0)
36+
self.cashflows = rng.standard_normal((n_cashflows, cashflow_lengths))
37+
38+
def time_2d_cashflow(self, n_cashflows, cashflow_lengths):
39+
npf.npv(0.08, self.cashflows)

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ pydata-sphinx-theme = "^0.14.3"
5656
[tool.poetry.group.lint.dependencies]
5757
ruff = "^0.1.6"
5858

59+
60+
[tool.poetry.group.bench.dependencies]
61+
asv = "^0.6.1"
62+

0 commit comments

Comments
 (0)