Liking cljdoc? Tell your friends :D

Arraymap and hashmap experimental merging benchmarks

Can a 'clever' algorithm merge two hashmaps faster than Clojure's merge and merge-with?

Observations: Nope. Cleverness is over-rated.

We previously established that we could merge two hashmaps a bit faster than Clojure's own merge using reduce-kv and transients. The experimental namespace provides merging implementations that attempt to be even faster by walking only the shorter hashmap once and using set operations to touch only what's absolutely necessary. These benchmarks clearly show that experiment is an utter failure.

Rob Pike, you win.

Merge tactics for large hashmaps

For hashmaps containing one to one-million key/value pairs, the experimental merge function is an order of magnitude slower than Smoosh's best merge.


Merge tactics for small arraymaps/hashmaps

For hashmaps containing one to sixteen key/value pairs, the experimental merge function is up to 30% slower than Smoosh's best merge.

(fn [n] ((merge-tactic) ((small-maps n) :left) ((small-maps n) :right)))

Benchmark measurements for expression `(fn [n] ((merge-tactic) ((small-maps n) :left) ((small-maps n) :right)))`, time versus 'n' arguments, comparing different versions. Show details
times in seconds, mean±std
arg, n
version 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
core-merge 1.4e-04±2.2e-06 1.4e-04±1.0e-06 1.4e-04±1.6e-06 1.4e-04±1.8e-06 1.4e-04±2.2e-06 1.4e-04±9.8e-07 1.4e-04±1.4e-06 1.4e-04±1.8e-06 1.4e-04±2.5e-06 1.4e-04±4.9e-07 1.4e-04±3.3e-06 1.4e-04±2.2e-06 1.4e-04±6.5e-07 1.4e-04±4.9e-06 1.5e-04±2.8e-06 1.5e-04±1.4e-06 1.5e-04±2.7e-06
experimental-merge 1.5e-04±5.9e-06 1.5e-04±1.3e-06 1.5e-04±2.8e-06 1.5e-04±2.1e-06 1.5e-04±2.2e-06 1.6e-04±1.8e-06 1.6e-04±7.9e-07 1.6e-04±1.4e-06 1.6e-04±4.3e-07 1.6e-04±1.0e-06 1.7e-04±1.5e-06 1.7e-04±2.5e-06 1.7e-04±1.2e-06 1.7e-04±2.4e-06 1.8e-04±3.2e-06 1.8e-04±2.9e-06 1.9e-04±3.9e-06
smerge 1.3e-04±7.6e-07 1.3e-04±8.8e-07 1.4e-04±1.6e-06 1.3e-04±2.3e-06 1.4e-04±1.7e-06 1.3e-04±2.5e-06 1.3e-04±6.2e-07 1.3e-04±1.1e-06 1.3e-04±6.2e-07 1.3e-04±1.1e-06 1.3e-04±2.0e-06 1.3e-04±8.7e-07 1.3e-04±8.2e-07 1.3e-04±1.0e-06 1.4e-04±2.2e-06 1.3e-04±3.1e-07 1.4e-04±1.3e-06

Merge-with addition tactics for large hashmaps

Same problem.

(fn [n] ((merge-with-tactic) + ((large-maps n) :left) ((large-maps n) :right)))

Benchmark measurements for expression `(fn [n] ((merge-with-tactic) + ((large-maps n) :left) ((large-maps n) :right)))`, time versus 'n' arguments, comparing different versions. Show details

Merge-with addition tactics for small hashmaps

And again.

(fn [n] ((merge-with-tactic) + ((small-maps n) :left) ((small-maps n) :right)))

Benchmark measurements for expression `(fn [n] ((merge-with-tactic) + ((small-maps n) :left) ((small-maps n) :right)))`, time versus 'n' arguments, comparing different versions. Show details
times in seconds, mean±std
arg, n
version 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
core-merge-with 1.4e-04±2.1e-06 1.4e-04±7.2e-07 1.4e-04±9.7e-07 1.4e-04±4.1e-07 1.4e-04±8.5e-07 1.4e-04±1.8e-06 1.4e-04±1.4e-06 1.4e-04±6.5e-07 1.4e-04±1.7e-06 1.4e-04±1.8e-06 1.4e-04±7.2e-07 1.5e-04±1.7e-06 1.5e-04±8.9e-07 1.4e-04±4.2e-07 1.5e-04±1.4e-06 1.5e-04±1.9e-06 1.5e-04±2.7e-06
experimental-merge-with 1.5e-04±9.6e-07 1.5e-04±8.8e-07 1.5e-04±5.8e-07 1.5e-04±1.2e-06 1.5e-04±1.3e-06 1.5e-04±2.1e-06 1.6e-04±5.9e-07 1.6e-04±2.0e-06 1.6e-04±6.4e-07 1.6e-04±5.6e-07 1.6e-04±1.2e-06 1.7e-04±2.2e-06 1.7e-04±8.8e-07 1.7e-04±6.0e-07 1.7e-04±2.3e-06 1.7e-04±7.2e-07 1.7e-04±1.4e-06
smerge-with 1.4e-04±2.2e-06 1.4e-04±1.2e-06 1.4e-04±3.3e-07 1.4e-04±1.5e-06 1.4e-04±6.4e-07 1.4e-04±7.7e-07 1.4e-04±2.4e-06 1.4e-04±5.5e-07 1.4e-04±2.0e-06 1.4e-04±1.4e-06 1.4e-04±1.3e-06 1.4e-04±2.4e-06 1.4e-04±7.4e-07 1.4e-04±5.6e-07 1.5e-04±2.0e-06 1.4e-04±6.0e-07 1.4e-04±3.2e-07

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close