Repository navigation
Add ASV benchmarks for add and subtract, including complex in-place - #292
Open
antonwolfy wants to merge 1 commit into
Open
antonwolfy wants to merge 1 commit into
antonwolfy wants to merge 1 commit into
Conversation
The ASV suite had no benchmark for add or subtract and no micro-benchmark for a complex dtype, so changes to those loops, such as the contiguous complex fast path in gh-278, did not show up in it. Add BenchAdd and BenchSubtract to micro/bench_micro.py, written like BenchArctan2 and BenchPower, for float32, float64, complex64 and complex128 at 10k, 100k and 1M elements. Add micro/bench_inplace.py with BenchAddInplace and BenchSubtractInplace for complex in-place calls (out=a, out=b and z += z) at 10k and 100k, where mkl_umath runs its own loops instead of oneMKL VM.
antonwolfy
requested review from
jharlow-intel,
ndgrigorian,
vlad-perevezentsev and
xaleryb
as code owners
October 20, 2026 14:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ASV suite has no benchmark for
addorsubtractand no micro-benchmark for a complex dtype. The contiguous complex fast path in #278 makes complexadd/subtractup to 2.4x faster, and the suite doesn't see it: its only complex coverage is the mandelbrot kernels, which moved by 0–2% with that change. This PR adds benchmarks that do.Changes
micro/bench_micro.py:BenchAddandBenchSubtract, written likeBenchArctan2andBenchPower(a new result array on each call), for float32, float64, complex64 and complex128 at 10k, 100k and 1M. The 10k and 100k sizes run mkl_umath's own loops and 1M calls oneMKL VM, since the threshold isn > 100000. A_uniformhelper draws the real and imaginary parts independently.micro/bench_inplace.py(new):BenchAddInplaceandBenchSubtractInplacefor complex64 and complex128 at 10k and 100k, with modesout=a,out=bandz += z. Each mode takes its own loop in perf: add contiguous fast path to complex add/subtract fallback loop #278.z += zstarts from zeros, because repeated doubling would overflow to inf.README.md: coverage table.That's 48 new benchmarks, 24 per file. On the host below they add about 30 s per pass.
Testing
Core Ultra 5 236V (Lunar Lake), conda-forge icx 2026.1.1, NumPy 2.5.4, MKL 2026.1.0,
MKL_NUM_THREADS=1, pinned to one P-core with turbo off.asv run --python=sameagainst two builds ofmain8ca254c (byte-identical, as an A/A control) and #278 at 1346ce2, with passes ordered main, main, #278, #278, main, main and samples appended.mainvsmain: nothing flagged, ratios 0.93–1.04.mainvs perf: add contiguous fast path to complex add/subtract fallback loop #278: 27 of 48 flagged as faster, 26 of them at 0.80 or below, so a change that undoes the fast path would trip the 20% regression threshold inasv.conf.json.Median time relative to
main, so below 1 is faster:mainBenchAdd/BenchSubtract, complex at 10k and complex64 at 100kBenchAdd/BenchSubtract, complex128 at 100kBenchAdd/BenchSubtract, complex at 1M (oneMKL)BenchAdd/BenchSubtract, float32 / float64z += zat 100kout=a/out=bat 100kThe complex128 in-place cases at 100k use two 1.6 MB arrays, more than the 2.5 MB L2, and ASV's spread there is ±5–10 µs. The same pattern outside ASV (fresh setup, one warm-up call, one timed call, 1,800 samples per build) gives 0.90–0.92 with an A/A of 1.00, so I read the ASV result as noise at that size.
Median times
Medians of 20 single-call samples, turbo off.
mainmainmainmainout=aout=bz += zout=aout=bz += zout=aout=bz += zout=aout=bz += zpre-commit passes on the changed files.
Notes
BenchArctan2andBenchPowertime stock NumPy.arctan2andpowerare commented out ingenerate_umath.py, sopatch_numpy_umath()leaves them alone.powergets mkl_umath loops in Add oneMKL power loops for float32 and float64 #285; both are left as they are here.