From c00d6767db26b5dfb4b4bba97edd22f9b31e23fd Mon Sep 17 00:00:00 2001 From: Ryan Xiao Wei Lin Date: Sun, 4 Oct 2026 09:49:58 +0100 Subject: [PATCH 1/5] BUG: add spin bench command for local benchmarks --- .spin/cmds.py | 28 ++++++++++++++++ doc/source/dev/running_the_benchmarks.md | 41 ++++++++++++++---------- pyproject.toml | 3 ++ 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/.spin/cmds.py b/.spin/cmds.py index ab34035..322975d 100644 --- a/.spin/cmds.py +++ b/.spin/cmds.py @@ -1,5 +1,33 @@ +import os +import sys + import click import spin +from spin.cmds import meson + + +@click.command() +@click.option('--quick', '-q', is_flag=True, + help='Run each benchmark once to check that it works.') +@click.option('--tests', '-t', multiple=True, + help='Select benchmarks by name or regular expression.') +@meson.build_dir_option +@click.pass_context +def bench(ctx, quick, tests, build_dir): + """Run benchmarks against the local build without saving results.""" + args = [sys.executable, '-m', 'asv', 'run', '--python=same', + '--dry-run', '--show-stderr'] + if quick: + args.append('--quick') + for test in tests: + args.extend(['--bench', test]) + ctx.invoke(meson.build, build_dir=build_dir) + meson._set_pythonpath(build_dir) + env = os.environ.copy() + # ASV removes PYTHONPATH unless it is explicitly passed this way. + env['ASV_PYTHONPATH'] = env.get('PYTHONPATH', '') + spin.util.run(args, env=env) + @click.command() @click.option( diff --git a/doc/source/dev/running_the_benchmarks.md b/doc/source/dev/running_the_benchmarks.md index ea1d679..9e2c2b5 100644 --- a/doc/source/dev/running_the_benchmarks.md +++ b/doc/source/dev/running_the_benchmarks.md @@ -4,42 +4,49 @@ This document outlines how to setup and run the benchmarks using [asv](https://a ## Running the benchmarks -To run the benchmarks with ``asv``, simply enter: +With the development environment activated, register your machine once: ```shell -asv run +asv machine --yes ``` -## Viewing the results +Then run: -There are two steps to viewing the results locally. The results need to be published and the launched in a local web browser. +```shell +spin bench +``` -To publish the results use: +This builds the local checkout and runs the benchmarks against that build, +including uncommitted changes. It uses the current Python environment and +does not save results. To select benchmarks by name or regular expression: ```shell -asv publish +spin bench -t Npv2D.time_broadcast ``` -And then to view the results: +For a quick check that the benchmarks run, use ``spin bench --quick``. +Quick runs are not suitable for reliable performance measurements. + +To benchmark committed revisions and save results for publishing, use ASV: ```shell -asv preview +asv run ``` -This will launch a local web browser from which you can view the results +## Viewing the results -## Dry runs +There are two steps to viewing the results locally. The results need to be published and the launched in a local web browser. -One common use case is to use ``asv`` in development, there are several useful flags that should be used: +To publish the results use: ```shell -asv --python=same --quick --dry-run +asv publish ``` -We are adding three flags, these flags are: +And then to view the results: -1. `--python=same` uses the same environment as your development environment (saves time to avoid building environments) -2. `--quick` only runs the benchmarks once -3. `--dry-run` to not save the results of the benchmarks +```shell +asv preview +``` -These can be useful for getting quick feedback during development, but should not be used as anything other than a rough guide. \ No newline at end of file +This will launch a local web browser from which you can view the results diff --git a/pyproject.toml b/pyproject.toml index 842b423..8172f8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,6 +101,9 @@ package = 'numpy_financial' "Documentation" = [ "spin.cmds.meson.docs" ] +"Benchmarks" = [ + ".spin/cmds.py:bench" +] "Environments" = [ "spin.cmds.meson.shell", "spin.cmds.meson.ipython", From 36e5933577f02ca33a8de031a442ab03f5ed005a Mon Sep 17 00:00:00 2001 From: Ryan Xiao Wei Lin Date: Sun, 4 Oct 2026 09:51:55 +0100 Subject: [PATCH 2/5] Remove optional quick benchmark flag --- .spin/cmds.py | 6 +----- doc/source/dev/running_the_benchmarks.md | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.spin/cmds.py b/.spin/cmds.py index 322975d..e689fba 100644 --- a/.spin/cmds.py +++ b/.spin/cmds.py @@ -7,18 +7,14 @@ @click.command() -@click.option('--quick', '-q', is_flag=True, - help='Run each benchmark once to check that it works.') @click.option('--tests', '-t', multiple=True, help='Select benchmarks by name or regular expression.') @meson.build_dir_option @click.pass_context -def bench(ctx, quick, tests, build_dir): +def bench(ctx, tests, build_dir): """Run benchmarks against the local build without saving results.""" args = [sys.executable, '-m', 'asv', 'run', '--python=same', '--dry-run', '--show-stderr'] - if quick: - args.append('--quick') for test in tests: args.extend(['--bench', test]) ctx.invoke(meson.build, build_dir=build_dir) diff --git a/doc/source/dev/running_the_benchmarks.md b/doc/source/dev/running_the_benchmarks.md index 9e2c2b5..d31076f 100644 --- a/doc/source/dev/running_the_benchmarks.md +++ b/doc/source/dev/running_the_benchmarks.md @@ -24,9 +24,6 @@ does not save results. To select benchmarks by name or regular expression: spin bench -t Npv2D.time_broadcast ``` -For a quick check that the benchmarks run, use ``spin bench --quick``. -Quick runs are not suitable for reliable performance measurements. - To benchmark committed revisions and save results for publishing, use ASV: ```shell From 4f62e2c511aa1c69edbb15750fbcb056c175ddf3 Mon Sep 17 00:00:00 2001 From: Naseweisssss <89737029+naseweisssss@users.noreply.github.com> Date: Sun, 4 Oct 2026 23:01:19 +0100 Subject: [PATCH 3/5] Update doc/source/dev/running_the_benchmarks.md Co-authored-by: Inessa Pawson --- doc/source/dev/running_the_benchmarks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dev/running_the_benchmarks.md b/doc/source/dev/running_the_benchmarks.md index d31076f..77a6fe3 100644 --- a/doc/source/dev/running_the_benchmarks.md +++ b/doc/source/dev/running_the_benchmarks.md @@ -18,7 +18,7 @@ spin bench This builds the local checkout and runs the benchmarks against that build, including uncommitted changes. It uses the current Python environment and -does not save results. To select benchmarks by name or regular expression: +does not save results. Because it is a dry run, the timings are only a rough guide and are not meant to be compared across sessions or machines. To select benchmarks by name or regular expression: ```shell spin bench -t Npv2D.time_broadcast From 46112eaff913082b0c44e4f2232798c90b87921d Mon Sep 17 00:00:00 2001 From: Naseweisssss <89737029+naseweisssss@users.noreply.github.com> Date: Sun, 4 Oct 2026 23:01:29 +0100 Subject: [PATCH 4/5] Update doc/source/dev/running_the_benchmarks.md Co-authored-by: Inessa Pawson --- doc/source/dev/running_the_benchmarks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dev/running_the_benchmarks.md b/doc/source/dev/running_the_benchmarks.md index 77a6fe3..54a4a79 100644 --- a/doc/source/dev/running_the_benchmarks.md +++ b/doc/source/dev/running_the_benchmarks.md @@ -32,7 +32,7 @@ asv run ## Viewing the results -There are two steps to viewing the results locally. The results need to be published and the launched in a local web browser. +There are two steps to viewing the results locally. The results need to be published and then launched in a local web browser. To publish the results use: From 00ef86745865a316b6c140f0522ba3b3947def44 Mon Sep 17 00:00:00 2001 From: Naseweisssss <89737029+naseweisssss@users.noreply.github.com> Date: Sun, 4 Oct 2026 23:31:04 +0100 Subject: [PATCH 5/5] Update .spin/cmds.py Co-authored-by: Inessa Pawson --- .spin/cmds.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.spin/cmds.py b/.spin/cmds.py index e689fba..91973eb 100644 --- a/.spin/cmds.py +++ b/.spin/cmds.py @@ -21,7 +21,8 @@ def bench(ctx, tests, build_dir): meson._set_pythonpath(build_dir) env = os.environ.copy() # ASV removes PYTHONPATH unless it is explicitly passed this way. - env['ASV_PYTHONPATH'] = env.get('PYTHONPATH', '') + if env.get('PYTHONPATH'): + env['ASV_PYTHONPATH'] = env['PYTHONPATH'] spin.util.run(args, env=env)