Benchmark results
View SourceFull tables behind the summary in the README.
Nanoseconds per operation (best of three) and memory in words for a list of
n integers, on OTP 29.1.3 on an Intel Core i9-14900KF running Linux, pinned
to its performance cores. The .beam is the one the proofs verify (same MD5).
skew_list_bench:run() reproduces the table.
| n | nth list | nth array | nth skew | update list | update array | update skew | cons+tl list | cons+tl queue | cons+tl skew | words list | words array | words skew |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16 | 22 ns | 9 ns | 26 ns | 143 ns | 88 ns | 73 ns | 6 ns | 17 ns | 18 ns | 32 | 44 | 42 |
| 256 | 131 ns | 11 ns | 50 ns | 1.8 µs | 68 ns | 125 ns | 6 ns | 17 ns | 17 ns | 512 | 316 | 522 |
| 4096 | 2.5 µs | 14 ns | 66 ns | 21.9 µs | 59 ns | 92 ns | 6 ns | 17 ns | 18 ns | 8192 | 4668 | 8202 |
| 65536 | 45.7 µs | 18 ns | 53 ns | 364.8 µs | 70 ns | 99 ns | 6 ns | 19 ns | 17 ns | 131072 | 74300 | 131082 |
| 1000000 | 499.6 µs | 30 ns | 81 ns | 8.3 ms | 94 ns | 112 ns | 7 ns | 18 ns | 17 ns | 2000000 | 1133400 | 2000028 |
nth/2beatslists:nth/2from about n = 64, andupdate/3beats rebuilding a plain list from n = 16.arrayis about 3 to 5 times faster fornthbut has no cheap front insert.cons+tlcosts about three times a plain list cons cell, because each call allocates the{skew_list, Len, Trees}wrapper; it matchesqueue.- Memory is the same as a plain list (2 words per element) plus about 10 words.
Tier 2, each next to the route through lists (to_list/1, the lists
function, then from_list/1 when the result is a skew list); append adds
16 elements at the end and prepend puts 16 in front (append(T, S)).
skew_list_bench:run_tier2() reproduces the table.
| n | foldl skew | foldl via lists | foldr skew | foldr via lists | map skew | map via lists | filter skew | filter via lists | append skew | append via lists | prepend skew | prepend via lists | reverse skew | reverse via lists |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16 | 68 ns | 128 ns | 82 ns | 124 ns | 94 ns | 218 ns | 163 ns | 192 ns | 259 ns | 286 ns | 254 ns | 287 ns | 139 ns | 170 ns |
| 256 | 964 ns | 2.0 µs | 1.3 µs | 2.2 µs | 1.4 µs | 3.2 µs | 2.2 µs | 2.6 µs | 2.1 µs | 2.7 µs | 347 ns | 2.3 µs | 1.9 µs | 2.5 µs |
| 4096 | 14.7 µs | 49.8 µs | 20.7 µs | 40.1 µs | 22.1 µs | 79.9 µs | 35.2 µs | 50.0 µs | 85.9 µs | 46.1 µs | 345 ns | 61.4 µs | 55.3 µs | 46.0 µs |
| 65536 | 243.3 µs | 561.4 µs | 332.2 µs | 685.7 µs | 390.2 µs | 859.2 µs | 596.5 µs | 722.5 µs | 755.9 µs | 811.5 µs | 342 ns | 826.3 µs | 694.8 µs | 855.7 µs |
| 1000000 | 3.8 ms | 9.8 ms | 5.2 ms | 10.1 ms | 10.5 ms | 19.9 ms | 10.4 ms | 15.4 ms | 10.7 ms | 19.0 ms | 367 ns | 16.7 ms | 10.6 ms | 18.2 ms |
foldl,foldrandmapwalk the trees directly and are 1.4 to 3 times faster than converting;mapgains most because it keeps the shapes.filter,appendandreverserebuild in one pass and are usually faster than the route throughlists, by up to about 1.8 times. At some sizes they are up to 1.5 times slower instead (appendat 4096 in an earlier run): the cost moves with where garbage collections fall, and the same size flips the other way with a larger initial heap (+hms).appendrebuilds while the second list is no longer than the first, and otherwise conses the first list's elements onto the second. Either way it is O(length(S1)), soprependtakes the same 350 ns or so at every size.
Tier 3, each next to the same operation on a plain list. sublist takes 16
elements from the middle, split cuts in half, and member searches for a
missing element. Memory is for duplicate(n, x).
skew_list_bench:run_tier3() reproduces the table.
| n | last list | last skew | sublist list | sublist skew | split list | split skew | duplicate list | duplicate skew | member list | member skew | words duplicate list | words duplicate skew |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16 | 21 ns | 11 ns | 35 ns | 139 ns | 44 ns | 106 ns | 61 ns | 41 ns | 10 ns | 55 ns | 32 | 26 |
| 256 | 511 ns | 15 ns | 207 ns | 181 ns | 596 ns | 716 ns | 895 ns | 60 ns | 235 ns | 709 ns | 512 | 42 |
| 4096 | 9.4 µs | 22 ns | 2.1 µs | 194 ns | 12.1 µs | 12.2 µs | 14.6 µs | 85 ns | 3.7 µs | 11.4 µs | 8192 | 58 |
| 65536 | 129.7 µs | 29 ns | 32.3 µs | 206 ns | 181.9 µs | 217.4 µs | 299.1 µs | 105 ns | 58.3 µs | 186.7 µs | 131072 | 74 |
| 1000000 | 2.0 ms | 57 ns | 502.2 µs | 236 ns | 4.3 ms | 4.5 ms | 4.4 ms | 291 ns | 912.5 µs | 3.0 ms | 2000000 | 420 |
last,sublist/3from the middle andduplicateuse the structure: O(log n) wherelistsis O(n), so thousands of times faster at 1,000,000.duplicatealso takes 420 words for a million copies, against 2,000,000.- From a few hundred elements,
splitis within about 1.2 times oflists:split/2, and level with it at 1,000,000: the suffix is O(log n), and the prefix is rebuilt in one pass. On very short lists the rebuild's fixed cost makes it about 2.5 times slower. memberis about three times slower than thelists:member/2BIF, which is written in C.
Tier 4, each next to the same operation on a plain list. zip pairs two
skew lists of n integers, unzip splits n pairs and mapfoldl maps and
sums. skew_list_bench:run_tier4() reproduces the table.
| n | zip list | zip skew | unzip list | unzip skew | mapfoldl list | mapfoldl skew |
|---|---|---|---|---|---|---|
| 16 | 104 ns | 121 ns | 96 ns | 159 ns | 142 ns | 173 ns |
| 256 | 1.6 µs | 1.6 µs | 1.6 µs | 2.4 µs | 2.1 µs | 2.2 µs |
| 4096 | 25.6 µs | 24.8 µs | 24.1 µs | 38.8 µs | 34.2 µs | 36.5 µs |
| 65536 | 431.4 µs | 423.4 µs | 455.6 µs | 659.5 µs | 572.6 µs | 595.5 µs |
| 1000000 | 17.5 ms | 6.3 ms | 10.9 ms | 15.9 ms | 12.7 ms | 11.9 ms |
zip,unzipandmapfoldlkeep the tree shapes and run within about 1.7 times oflistseither way (unzipis the slowest); they are there for convenience, not speed. At 1,000,000,zipis about 2.8 times faster.