Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created May 4, 2012 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/2598523 to your computer and use it in GitHub Desktop.
Save michalmarczyk/2598523 to your computer and use it in GitHub Desktop.
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