Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Benchmarks for CLJS protocol dispatch
(ns timings)
(defn -main []
(println ";;; satisfies?")
(println "(satisfies? ISeq (list 1 2 3))")
(let [coll (list 1 2 3)] (time (dotimes [_ 10000000] (satisfies? ISeq coll))))
(println "(satisfies? ISeq [1 2 3])")
(let [coll [1 2 3]] (time (dotimes [_ 10000000] (satisfies? ISeq coll))))
(println)
(println ";;; list ops")
(println "(first (list 1 2 3))")
(let [coll (list 1 2 3)] (time (dotimes [_ 1000000] (first coll))))
(println "(-first (list 1 2 3))")
(let [coll (list 1 2 3)] (time (dotimes [_ 1000000] (-first coll))))
(println "(rest (list 1 2 3))")
(let [coll (list 1 2 3)] (time (dotimes [_ 1000000] (rest coll))))
(println "(next (list 1 2 3))")
(let [coll (list 1 2 3)] (time (dotimes [_ 1000000] (next coll))))
(println)
(println ";;; vector ops")
(println "(first [1 2 3])")
(let [coll [1 2 3]] (time (dotimes [_ 1000000] (first coll))))
(println "(rest [1 2 3])")
(let [coll [1 2 3]] (time (dotimes [_ 1000000] (rest coll))))
(println "(next [1 2 3])")
(let [coll [1 2 3]] (time (dotimes [_ 1000000] (next coll))))
(println)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.