Benchmark results

View Source

Full 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.

nnth listnth arraynth skewupdate listupdate arrayupdate skewcons+tl listcons+tl queuecons+tl skewwords listwords arraywords skew
1622 ns9 ns26 ns143 ns88 ns73 ns6 ns17 ns18 ns324442
256131 ns11 ns50 ns1.8 µs68 ns125 ns6 ns17 ns17 ns512316522
40962.5 µs14 ns66 ns21.9 µs59 ns92 ns6 ns17 ns18 ns819246688202
6553645.7 µs18 ns53 ns364.8 µs70 ns99 ns6 ns19 ns17 ns13107274300131082
1000000499.6 µs30 ns81 ns8.3 ms94 ns112 ns7 ns18 ns17 ns200000011334002000028
  • nth/2 beats lists:nth/2 from about n = 64, and update/3 beats rebuilding a plain list from n = 16.
  • array is about 3 to 5 times faster for nth but has no cheap front insert.
  • cons + tl costs about three times a plain list cons cell, because each call allocates the {skew_list, Len, Trees} wrapper; it matches queue.
  • 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.

nfoldl skewfoldl via listsfoldr skewfoldr via listsmap skewmap via listsfilter skewfilter via listsappend skewappend via listsprepend skewprepend via listsreverse skewreverse via lists
1668 ns128 ns82 ns124 ns94 ns218 ns163 ns192 ns259 ns286 ns254 ns287 ns139 ns170 ns
256964 ns2.0 µs1.3 µs2.2 µs1.4 µs3.2 µs2.2 µs2.6 µs2.1 µs2.7 µs347 ns2.3 µs1.9 µs2.5 µs
409614.7 µs49.8 µs20.7 µs40.1 µs22.1 µs79.9 µs35.2 µs50.0 µs85.9 µs46.1 µs345 ns61.4 µs55.3 µs46.0 µs
65536243.3 µs561.4 µs332.2 µs685.7 µs390.2 µs859.2 µs596.5 µs722.5 µs755.9 µs811.5 µs342 ns826.3 µs694.8 µs855.7 µs
10000003.8 ms9.8 ms5.2 ms10.1 ms10.5 ms19.9 ms10.4 ms15.4 ms10.7 ms19.0 ms367 ns16.7 ms10.6 ms18.2 ms
  • foldl, foldr and map walk the trees directly and are 1.4 to 3 times faster than converting; map gains most because it keeps the shapes.
  • filter, append and reverse rebuild in one pass and are usually faster than the route through lists, by up to about 1.8 times. At some sizes they are up to 1.5 times slower instead (append at 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).
  • append rebuilds 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)), so prepend takes 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.

nlast listlast skewsublist listsublist skewsplit listsplit skewduplicate listduplicate skewmember listmember skewwords duplicate listwords duplicate skew
1621 ns11 ns35 ns139 ns44 ns106 ns61 ns41 ns10 ns55 ns3226
256511 ns15 ns207 ns181 ns596 ns716 ns895 ns60 ns235 ns709 ns51242
40969.4 µs22 ns2.1 µs194 ns12.1 µs12.2 µs14.6 µs85 ns3.7 µs11.4 µs819258
65536129.7 µs29 ns32.3 µs206 ns181.9 µs217.4 µs299.1 µs105 ns58.3 µs186.7 µs13107274
10000002.0 ms57 ns502.2 µs236 ns4.3 ms4.5 ms4.4 ms291 ns912.5 µs3.0 ms2000000420
  • last, sublist/3 from the middle and duplicate use the structure: O(log n) where lists is O(n), so thousands of times faster at 1,000,000. duplicate also takes 420 words for a million copies, against 2,000,000.
  • From a few hundred elements, split is within about 1.2 times of lists: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.
  • member is about three times slower than the lists:member/2 BIF, 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.

nzip listzip skewunzip listunzip skewmapfoldl listmapfoldl skew
16104 ns121 ns96 ns159 ns142 ns173 ns
2561.6 µs1.6 µs1.6 µs2.4 µs2.1 µs2.2 µs
409625.6 µs24.8 µs24.1 µs38.8 µs34.2 µs36.5 µs
65536431.4 µs423.4 µs455.6 µs659.5 µs572.6 µs595.5 µs
100000017.5 ms6.3 ms10.9 ms15.9 ms12.7 ms11.9 ms
  • zip, unzip and mapfoldl keep the tree shapes and run within about 1.7 times of lists either way (unzip is the slowest); they are there for convenience, not speed. At 1,000,000, zip is about 2.8 times faster.