Sorting
Sort two million pseudo-random 32-bit integers.
cpu-boundmemory-bounddata-structures
What is measured
Each iteration receives a fresh array of 2,000,000 pseudo-random 32-bit integers (MINSTD, seed = iteration), sorts it ascending with the standard library sort and returns it. Only the sort is timed; the whole sorted array is hashed afterwards.
Pseudocode
a = decode(instance) # 2,000,000 int32, a new instance every iteration (untimed)
start timer
sort a ascending # standard library sort
stop timer
hash every element of a # untimedReveals: Comparison and memory-access efficiency of the default sort.
Caveat: Algorithm and stability differ (introsort, pdqsort, timsort, V8 typed-array sort). Node uses Int32Array.sort and Python list.sort on plain ints - the idiomatic fast path of each. Haskell sorts a linked list with Data.List.sort and OCaml uses Array.stable_sort; Elixir sorts a list with Enum.sort.
Results (newest release of each language)
| Language / build | Time (× vs best) | |
|---|---|---|
| Go 1.27 · GOAMD64=v3 go build | 163 ms (1.01×) | |
| Go 1.27 · go builddefault | 164 ms (1.02×) | |
| C 16 · gcc -O3 | 261 ms (1.62×) | |
| C 16 · gcc -O2 | 262 ms (1.62×) | |
| C 16 · gcc -O3 -march=nativedefault | 267 ms (1.66×) | |
| Python 3.15 · python3default | 756 ms (4.68×) |
Click a language to see the source code, build flags, every session and how the number was computed.