language-bench

String operations

Build, scan and transform a 6.5 MB multilingual string.

memory-boundstrings

What is measured

Each iteration receives a 6.7 MB UTF-8 text of 1,000,000 words drawn from an ASCII + Latin + Cyrillic + CJK vocabulary (padded with spaces to a fixed length; the words depend on the iteration). The text is decoded into the language's own string type untimed; the timed part counts bytes, Unicode code points, words (spaces + 1) and non-overlapping occurrences of a needle, and computes a checksum after replacing spaces. No locale-dependent case mapping is used.

Pseudocode

text = decode(instance)               # UTF-8 -> native string, untimed
start timer
bytes      = length of text in UTF-8
codepoints = number of Unicode code points
words      = number of spaces + 1
needle     = non-overlapping occurrences of "er"
checksum   = sum of the UTF-8 bytes of text with ' ' replaced by '_'
stop timer

Reveals: Allocation, copying and Unicode handling costs.

Caveat: ASCII vs multilingual data changes results; strings are UTF-8 in C/C++/Go/Rust/Ruby/PHP but UTF-16 in Node, Java and C#, and code-point arrays in Python, so code-point counting is intrinsically different work.

Results (newest release of each language)

Language / buildTime (× vs best)
C 16 · gcc -O316.5 ms (1.02×)
C 16 · gcc -O3 -march=nativedefault16.6 ms (1.02×)
C 16 · gcc -O218.9 ms (1.16×)
Go 1.27 · go builddefault37.7 ms (2.33×)
Go 1.27 · GOAMD64=v3 go build37.9 ms (2.34×)
Python 3.15 · python3default72.6 ms (4.48×)

Click a language to see the source code, build flags, every session and how the number was computed.