Times are the geometric mean of the language's median times over the 10 tests.
In-memory disjoint-set forest (union-find) over the elements 0 .. n-1, with a union heuristic and path shortening. Every implementation on this page was written by an AI model from the same prompt, then tested and timed by the same harness.
Results: claude-opus-5-5_high
Entries n = 4,000,000
Samples 2 per cell (1 process × 2 timed repetitions, after 1 warm-up in each process)
Measured 2026-11-23 08:33 UTC-07:00
Machine Apple M3, 8 cores, 16 GB, macOS 27.0.1
Model was told 10,000,000 entries on Apple M4 Max (arm64), 36 GB (not what was measured)
Benchmark run time 10m 32s (C 0m 09s, C++ 0m 10s, Rust 0m 10s, Go 0m 15s, Zig 0m 11s, Swift 0m 10s, Java 0m 14s, C# 0m 12s, Node.js 0m 46s, Bun 0m 38s, Python 7m 36s)
Median time per case (ms)
Case
C
C++
Rust
Go
Zig
Swift
Java
C#
Node.js
Bun
Python
Random unions
1821.03×
2011.14×
1761.00×
3381.92×
2091.19×
1891.07×
2451.39×
2191.25×
3662.08×
2991.70×
5,57931.70×
Chain
3601.63×
2311.04×
2781.25×
4361.97×
5772.61×
3721.68×
2751.24×
2221.00×
2641.19×
2261.02×
12,81457.81×
Balanced merging
69.21.03×
75.71.13×
67.21.00×
1502.23×
1131.67×
77.51.15×
1301.94×
1201.79×
1632.43×
1321.96×
9,147136.11×
Find, deep trees
2381.00×
2541.06×
2401.00×
3221.35×
2521.06×
2591.09×
3771.58×
2551.07×
3701.55×
2641.11×
7,16730.06×
Connected, same set
1411.00×
1801.27×
1851.31×
3092.19×
1661.18×
1651.17×
2261.60×
1941.38×
3292.33×
2231.58×
16,540117.16×
Connected, random
1611.00×
2091.30×
1941.21×
2901.80×
1871.16×
1641.02×
2041.27×
1691.05×
3061.90×
3822.37×
8,28951.53×
Set sizes
1751.01×
1871.07×
1741.00×
2641.52×
1891.09×
1881.08×
2601.49×
2031.17×
2911.67×
2091.20×
8,81450.68×
Grid percolation
2181.05×
2081.01×
2161.04×
3041.47×
2351.14×
2071.00×
2581.25×
2831.36×
3031.46×
2131.03×
5,87628.38×
Kruskal, small graphs
3221.00×
3331.04×
3231.00×
5801.80×
3901.21×
3351.04×
4221.31×
3581.11×
5251.63×
3981.24×
9,07128.20×
Mixed, small
3831.00×
4461.17×
3981.04×
5561.45×
4511.18×
4361.14×
5171.35×
4831.26×
6031.58×
5011.31×
5,92815.50×
Overall (geometric mean)
2021.00×
2131.05×
2061.02×
3321.64×
2471.22×
2161.07×
2721.35×
2341.15×
3321.64×
2661.31×
8,41941.61×
Median time per case, log scale (ms)
Random unionsChainBalanced mergingFind, deep treesConnected, same setConnected, randomSet sizesGrid percolationKruskal, small graphsMixed, small
4n unions: 4 times, n random pairs of elements are united, starting from n new singletons, which ends with one giant set and many small ones.
Chain
28(n-1) unions: 28 times, union(i, i+1) over all the elements, for ascending i in even rounds and descending i in odd rounds (one of the two orders builds a single long path without a union heuristic).
Balanced merging
7(n-1) unions: 7 times, the elements in a random order are merged level by level, sets of 1, 2, 4, ... elements in pairs through arbitrary members, until one set is left.
Find, deep trees
7n finds of random elements: 7 times, n finds on a forest built (untimed) as deep as the union heuristic allows, sets of 2^20 scattered elements in trees of 20 levels, whose paths the finds shorten.
Connected, same set
14n connected queries (14 passes over n pairs) on a forest of sets of 1024 random elements, where 90% of the pairs lie in the same set.
Connected, random
14n connected queries (14 passes over n random pairs) on the same forest of sets of 1024 elements, where the pairs are almost never in the same set.
Set sizes
10n set_size queries (10 passes over n random elements) on a forest made by n/2 random unions, which leaves sets of very different sizes.
Grid percolation
About 6n operations: 6 times, the n/2 cells of a 2236 x 2236 grid are opened in random order, each united with its open neighbours (and a virtual top or bottom element), and after every 2236 openings connected asks whether top and bottom are joined.
Kruskal, small graphs
20n unions: Kruskal's algorithm on n/16384 graphs of 4096 vertices and 16384 random edges, each on a new 4096-element structure that fits in the CPU caches, all run 20 times; union says whether an edge joins two components.
Mixed, small
10n operations in streams of 131072 on new 65536-element structures that fit in the CPU caches: 40% union, 50% connected, 10% set_size of random elements, so that each stream grows singletons into one giant set.
Method
Each language has a benchmark-owned driver (a line-for-line port of one canonical driver, in lang/) that calls the model-written data structure. The model does not write or control any timing code.
The driver times only the loop of operations, with an in-process monotonic clock. Process and runtime start-up, workload generation, pre-populating the structure, and verification are outside the timed region.
Every process runs a discarded warm-up repetition first (which is when a JIT compiles the hot code), then the timed repetitions, each on a freshly built structure. The number of processes and repetitions is the same for every language. Garbage-collected runtimes get one explicit collection before the timer starts; collections during the timed loop are counted.
Every repetition's results are checked against a reference, so a time is only reported for a correct run.
A language's overall score is the geometric mean of its median times over all cases. Unlike a total, that gives every case the same weight however long it runs, and being twice as slow on any one case costs the same. A language is only ranked if it completed every case.
All languages are compiled with fixed optimising flags and run single-threaded; see the README for the exact commands.