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: gemini-4-neon_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 21:46 UTC-07:00
Machine Apple M3, 8 cores, 16 GB, macOS 27.0.1
Model was told 4,000,000 entries on Apple M3 (arm64), 16 GB (as measured)
Benchmark run time 10m 32s (C 0m 08s, C++ 0m 08s, Rust 0m 08s, Go 0m 13s, Zig 0m 08s, Swift 0m 08s, Java 0m 14s, C# 0m 12s, Node.js 0m 46s, Bun 0m 39s, Python 7m 48s)
Median time per case (ms)
Case
C
C++
Rust
Go
Zig
Swift
Java
C#
Node.js
Bun
Python
Random unions
1361.08×
1351.07×
1461.16×
2471.96×
1341.06×
1261.00×
2491.97×
2291.82×
3072.43×
3042.41×
5,05940.12×
Chain
4352.26×
3321.72×
3621.88×
4422.29×
2971.54×
3571.85×
2421.25×
2471.28×
2981.55×
1931.00×
13,38269.43×
Balanced merging
87.71.17×
85.51.14×
88.51.18×
1421.89×
75.01.00×
86.31.15×
1461.94×
1481.98×
1772.36×
1241.66×
9,344124.51×
Find, deep trees
2311.16×
2111.06×
2001.00×
2611.31×
2081.04×
2221.11×
3201.60×
2231.12×
3171.59×
2301.15×
7,05435.31×
Connected, same set
1431.11×
1451.12×
1461.13×
2602.02×
1291.00×
1731.34×
2101.63×
1871.45×
2952.29×
2712.10×
19,225149.09×
Connected, random
1591.08×
1511.03×
1601.09×
2081.42×
1461.00×
1851.26×
1871.28×
1781.21×
3962.71×
4433.02×
9,10862.18×
Set sizes
55.91.09×
51.51.00×
54.41.06×
2084.03×
51.81.01×
54.71.06×
2454.75×
1973.83×
2845.52×
2504.86×
8,808170.94×
Grid percolation
1771.00×
1861.06×
1931.10×
2621.49×
1761.00×
1921.09×
2551.45×
2461.40×
2711.54×
2651.51×
5,29830.15×
Kruskal, small graphs
2721.06×
2631.02×
2851.11×
4491.75×
2571.00×
2621.02×
5121.99×
4401.71×
4871.90×
5482.13×
8,73133.97×
Mixed, small
2641.03×
2861.11×
2741.07×
5081.98×
2571.00×
2851.11×
5802.25×
5332.07×
6212.41×
6482.52×
5,67822.08×
Overall (geometric mean)
1691.11×
1621.06×
1681.10×
2781.81×
1531.00×
1711.12×
2701.76×
2431.59×
3272.14×
2931.92×
8,42855.08×
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.