Performance¶
How the numbers are produced¶
benchmarks/benchmark.py measures every function against named baselines and writes a
JSON report; benchmarks/render_tables.py renders the tables below from that report
into the README, so they always describe one real run on one named machine. The rules
the harness follows:
Every ratio names its baseline: a pure-Python loop over a list, the NumPy two-real-dot single-bin DFT,
np.fft.rfftfor one bin or for all bins, orsliding_window_view+rfftfor windows.Threads are pinned and reported. The thread sweep runs each thread count in its own subprocess with
OMP_NUM_THREADSset. A multi-threaded fastgoertzel number is never shown against a single-threaded baseline without saying so.Minimum of repeated rounds is the headline; the median is kept in the JSON to expose noise.
The machine is recorded: CPU, core count, OS, Python, NumPy, fastgoertzel version and the kernel build selected.
Per-call latency is measured separately, as percentiles over 100,000 calls with Python overhead included, because that is what a real-time loop cares about.
Numbers on other machines will differ; run make bench and make readme-tables and
quote your own together with the baseline and thread count. tests/test_performance.py
guards against large regressions with machine-independent ratio checks.
How to read them¶
One frequency is single-threaded by design. The Goertzel recurrence is a dependency chain that costs a few cycles per sample however the loop is written; signals of 1,024 samples or more are therefore split into independent blocks of at least 512 samples (up to eight) whose results are combined exactly, which keeps the FMA units busy. The hot loops are compiled for baseline x86-64 and for AVX2+FMA and the build is chosen at import.
Several frequencies. On one thread a batch costs the same per frequency as a single call: both run eight chains and are compute-bound once the signal is in cache. What the batch adds is OpenMP over lane groups, and one pass over the data per eight frequencies when the signal is larger than cache.
Sliding windows use the sliding-DFT update (constant cost per hop, re-synchronised exactly every 256 windows), so the window length no longer matters. What remains per window in the
(value, phase)form is mostlysqrtandatan2, whichgoertzel_sliding_batch_complexskips.Per-call latency includes Python call overhead. Calls that enter an OpenMP region carry a heavier tail: pass
threads=1or keep the work below the 65,536 operation threshold for predictable latency on small inputs.
Measured¶
Measured with python benchmarks/benchmark.py on Intel(R) Core(TM) i9-14900KF (32 logical cores), Windows-10-10.0.26300-SP0, Python 3.11.9, NumPy 2.3.4, fastgoertzel 2.0.0, avx2 kernel. Each time is the minimum of the timing rounds; ratios are baseline time over fastgoertzel time.
One frequency, goertzel(x, f), single-threaded:
N |
fastgoertzel |
pure-Python loop |
NumPy 2x real dot |
|
|---|---|---|---|---|
100 |
0.6 us |
2.8 us (4.7x) |
3.1 us (5.2x) |
4.1 us (6.9x) |
1,000 |
1.7 us |
24.5 us (14.0x) |
10.3 us (5.9x) |
7.3 us (4.2x) |
10,000 |
4.6 us |
232.3 us (50.7x) |
79.3 us (17.3x) |
39.9 us (8.7x) |
100,000 |
39.4 us |
2.37 ms (60.1x) |
926.7 us (23.5x) |
439.1 us (11.1x) |
1,000,000 |
386.2 us |
23.79 ms (61.6x) |
10.99 ms (28.5x) |
8.71 ms (22.6x) |
10,000,000 |
4.08 ms |
not run |
123.71 ms (30.4x) |
154.21 ms (37.8x) |
Several frequencies, goertzel_batch(x, freqs) (OpenMP default threads):
N |
M |
fastgoertzel |
M x |
|
M x NumPy dot |
|---|---|---|---|---|---|
1,000 |
8 |
4.3 us |
14.5 us (3.4x) |
6.2 us (1.5x) |
94.1 us (22.0x) |
100,000 |
8 |
46.8 us |
320.1 us (6.8x) |
449.8 us (9.6x) |
7.40 ms (158.0x) |
1,000,000 |
8 |
341.3 us |
3.12 ms (9.2x) |
8.67 ms (25.4x) |
89.01 ms (260.8x) |
1,000,000 |
64 |
2.22 ms |
24.95 ms (11.2x) |
10.09 ms (4.5x) |
643.91 ms (289.7x) |
10,000,000 |
8 |
4.08 ms |
32.86 ms (8.1x) |
151.49 ms (37.2x) |
1.038 s (254.7x) |
Sliding windows, goertzel_sliding_batch(x, W, freqs) (OpenMP default threads):
N |
W |
M |
fastgoertzel |
NumPy |
|---|---|---|---|---|
10,000 |
256 |
8 |
132.1 us |
8.26 ms (62.5x) |
10,000 |
256 |
64 |
3.27 ms |
21.19 ms (6.5x) |
100,000 |
256 |
8 |
2.86 ms |
90.93 ms (31.8x) |
100,000 |
1024 |
8 |
2.85 ms |
317.31 ms (111.3x) |
OpenMP scaling, batch N = 1e6, M = 32 and sliding N = 1e5, W = 256, M = 8; the last column reuses one preallocated out= array across calls:
OMP_NUM_THREADS |
batch |
sliding |
sliding, |
|---|---|---|---|
1 |
12.34 ms |
11.99 ms |
9.83 ms |
2 |
6.27 ms |
7.60 ms |
5.06 ms |
4 |
3.32 ms |
5.90 ms |
2.74 ms |
8 |
1.97 ms |
3.77 ms |
2.22 ms |
16 |
1.35 ms |
2.59 ms |
1.51 ms |
default |
1.28 ms |
2.73 ms |
1.32 ms |
Per-call latency, 100,000 calls each, Python overhead included:
Call |
p50 |
p90 |
p99 |
p99.9 |
max |
|---|---|---|---|---|---|
goertzel N=64 |
0.6 us |
0.6 us |
1.1 us |
2.2 us |
61 us |
goertzel N=256 |
0.8 us |
0.9 us |
1.4 us |
4.7 us |
125 us |
goertzel N=1024 |
1.0 us |
1.0 us |
1.6 us |
7.9 us |
107 us |
goertzel N=4096 |
2.2 us |
2.3 us |
3.1 us |
11.2 us |
141 us |
batch N=256 M=8 (serial) |
2.1 us |
2.2 us |
3.4 us |
14.9 us |
295 us |
batch N=65536 M=8 (OpenMP) |
33.7 us |
41.4 us |
95.0 us |
337.2 us |
425 us |
sliding N=1024 W=256 M=4 |
36.3 us |
39.3 us |
64.9 us |
122.5 us |
973 us |
sliding (out=) N=1024 W=256 M=4 |
35.9 us |
37.2 us |
63.9 us |
127.2 us |
694 us |
np.fft.rfft N=256 (reference) |
3.5 us |
3.9 us |
5.3 us |
33.5 us |
606 us |
NumPy 2x dot N=256 (reference) |
4.7 us |
4.8 us |
6.1 us |
33.6 us |
317 us |