Skip to content

[DO NOT MERGE] Archive simdutf-swift 1.0.1 String API benchmarks - #2

Draft
mrousavy wants to merge 1 commit into
mainfrom
benchmarks/string-apis-1.0.1
Draft

mrousavy wants to merge 1 commit into
mainfrom
benchmarks/string-apis-1.0.1

Conversation

@mrousavy

Copy link
Copy Markdown
Member

Archival draft — DO NOT MERGE. Keep this PR in draft and unmerged.

Archives the standalone simdutf-swift 1.0.1 String API benchmark harness, recorded samples, readable result tables, and reproduction scripts under Benchmarks/StringAPIs/.

Full benchmark report · Benchmark code · Per-case CSV · Raw samples and metadata

Results

Measured on Apple M2 Pro, macOS 27.0, Swift 6.4, using simdutf's ARM NEON backend. The harness pins the released 1.0.1 dependency independently of the parent package checkout.

Unicode cases use Latin, CJK, emoji, and mixed text at nominal sizes of 1,024–1,048,576 UTF-16 code units. Ranges below are minimum and maximum case-median speedups across those corpora and sizes. ASCII peaks come from separate ASCII cases; the full report identifies their exact sizes and timings. Allocation, buffer borrowing, and output destruction are included.

Default release: Swift -O, C++ -Os

Conversion Unicode geometric mean Unicode range ASCII peak
UTF-16 buffer → String 1.52× 1.13–2.43× 19.03×
UTF-32 buffer → String 7.61× 4.16–18.97× 55.70×
String → UTF-16 buffer 2.95× 2.40–3.90× 45.12×
String → UTF-32 buffer 9.51× 6.19–13.71× 62.74×

Opt-in comparison: Swift -O, C++ -O3

Conversion Unicode geometric mean Unicode range ASCII peak
UTF-16 buffer → String 1.60× 1.27–2.52× 24.01×
UTF-32 buffer → String 7.60× 4.13–18.83× 54.79×
String → UTF-16 buffer 3.66× 3.05–4.17× 69.58×
String → UTF-32 buffer 10.35× 6.70–15.22× 71.85×

Ordinary Swift baselines are String(decoding:as:) for constructors, Array(string.utf16) for UTF-16 buffers, and string.unicodeScalars.map { $0.value } for UTF-32 buffers. Across 64 equally weighted valid non-ASCII cases, geometric-mean speedups are 4.24× default and 4.63× with C++ -O3.

The report also compares temporary-buffer filling, public transcode, and the newer UTF8Span scalar iterator. Against the fastest measured standard-library comparator for each case, the overall geometric means are 3.08× and 3.41×.

The default 62.74× peak converts a 16 KiB ASCII String into UTF-32, versus the ordinary scalar-map/Array approach: 61.870 µs → 0.986 µs. The two process ratios were 62.42× and 62.21×; the headline uses the ratio of pooled medians.

Tiny outgoing strings can favor standard Swift temporary buffers. String(decodingUTF8:) uses Swift's decoder and is effectively unchanged. The report separates malformed-input, Foundation, and empty-string measurements. These are warm API microbenchmarks on the stated machine and toolchain.

Reproduce

cd Benchmarks/StringAPIs
python3 run.py
python3 report.py

Fresh measurements and their generated report go into ignored Results/local/; archived samples stay intact. Both optimization modes build before serial timing begins.

To regenerate the archived tables without running benchmarks:

python3 analysis.py --results-dir Results/1.0.1-m2-pro-swift6.4
python3 report.py --results-dir Results/1.0.1-m2-pro-swift6.4 --output README.md

Validation

  • Packaged release harness builds successfully and passes 491 full-output checks, including embedded nulls, malformed UTF-16/UTF-32, and comparison algorithms.
  • Recorded data contains 30,008 samples across four successful processes: two per optimization mode, with 11 samples per variant per process.
  • Archived tables regenerate from raw samples; harness and dependency hashes match the measured sources.
  • Runner and report smoke checks pass, with fresh output isolated from archived data.
  • git diff --check passes.

@mrousavy mrousavy added the documentation Improvements or additions to documentation label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant