Liking cljdoc? Tell your friends :D

get* performance

get* delegates to clojure.core/get or clojure.core/nth as appropriate, so its performance ought to be similar, aside from some minimal overhead for dispatching.

See the overall summary for benchmarking details. The benchmarks displayed in this document are defined here.

Hashmaps

Version 5 get* for a hashmap is very similar, even replicating the anomalous dip at 100.

(fn [n] (get (map-of-n-key-vals n) (dec n)))

Benchmark measurements for expression `(fn [n] (get (map-of-n-key-vals n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

(fn [n] (get* (map-of-n-key-vals n) (dec n)))

Benchmark measurements for expression `(fn [n] (get* (map-of-n-key-vals n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

Lists

This benchmark is unfair to get*: clojure.core/get always returns nil when given a list, whereas get* actually retrieves the nth element. The logarithmic behavior is expected for linked lists constructed from the head.

(fn [n] (get (list-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get (list-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

(fn [n] (get* (list-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get* (list-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

Sequences

Version 5 get* very closely provides the performance of clojure.core/nth, a notable improvement from version 4.

(fn [n] (get (seq-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get (seq-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

(fn [n] (get* (seq-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get* (seq-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

Vectors

Version 5

get* approaches clojure.core/get, being 19% slower for one-element vectors and linearly improving to matching the performance for one-million-element vectors.

(fn [n] (get (vec-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get (vec-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

(fn [n] (get* (vec-of-n-rand-ints n) (dec n)))

Benchmark measurements for expression `(fn [n] (get* (vec-of-n-rand-ints n) (dec n)))`, time versus 'n' arguments, comparing different versions. Show details

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