10 · Reference
Benchmarks
Numbers with the method next to them, including the rows where the library is slower.
Method
- Every measurement runs in a separate process: peak RSS is process-wide, so timing and memory cannot share one.
- Median and p95 over repeated runs; the corpus is generated by the harness so it is reproducible.
- Correctness is checked in the same run: decoded PCM is compared with libsndfile.
- Hardware: Apple M5 Pro, macOS 26.6.2, Python 3.14.7, release build with
lto = "fat"andopt-level = 3.
Scoreboard
| Axis | sound_rs | Competitor | Ratio |
|---|---|---|---|
| Import, cold process | 1.1 ms | 31.8 ms (soundfile) | 29× |
| Metadata, 60 s file | 1.2 ms | 31.7 ms | 26× |
| Decode WAV | 130 ms | 157 ms | 1.2× |
| Decode FLAC | 265 ms | 455 ms | 1.7× |
| Decode MP3 | 241 ms | 268 ms | 1.1× |
| Decode AAC | 349 ms | not supported | — |
| Time to first sound, 10 min | 11.3 ms | 302 ms | 27× |
| Peak RSS, 10 min file | 43 MB | 256 MB | 6× |
| Playback overhead, 3 s tone | 30 ms | 241 ms | 8× |
| Batch decode, 2 FLAC files | 177 ms | 299 ms | 1.7× |
Decode detail
60 seconds of stereo 44.1 kHz, median and p95 over seven runs.
| Format | sound_rs | libsndfile | PCM check |
|---|---|---|---|
| WAV 16-bit | 131 / 160 ms | 155 ms | identical |
| FLAC | 265 / 267 ms | 465 ms | identical |
| MP3 | 247 / 249 ms | 272 ms | 1.6·10⁻⁵, 47 samples offset |
| M4A (AAC) | 361 / 365 ms | unsupported | 8·10⁻⁸ vs ffmpeg |
Playback and memory
| First sound | Peak RSS | Overhead | |
|---|---|---|---|
| sound_rs Player, 10 min stream | 11.3 ms | 43 MB | +30 ms |
| soundfile + sounddevice | 302 ms | 256 MB | +241 ms |
The playback overhead row is a 3-second tone: wall clock minus the track duration. The
player number uses a stream that is already open; the one-shot play_array pays
the device setup and lands around +180 ms.
Reproduce it
python bench/run.py # sound_rs only
python bench/run.py --compare # + soundfile / sounddevice
python bench/run.py --reps 9
The harness generates its corpus (3 s and 10 min, WAV plus MP3/FLAC/M4A when ffmpeg is available), runs each measurement in a subprocess, and prints median, p95 and peak RSS. A full run takes about three minutes on the machine above.
Where it loses
- MP3 alignment: 47 samples (~1 ms) earlier than libsndfile and ffmpeg. Length is exact; values match after alignment.
- WAV decode: a memcpy race with libsndfile, 1.2× is all there is.
- AAC decode is slower than the other formats — a newer decoder with less tuning — though libsndfile cannot decode it at all.
- Very small files: for a 3-second tone the fixed device setup dominates everything, and all libraries land within a few tens of milliseconds of each other.