Skip to content

Instantly share code, notes, and snippets.

@runejuhl
Created February 20, 2020 10:53
Show Gist options
  • Save runejuhl/339e886b05a5d970379c846f2678fe11 to your computer and use it in GitHub Desktop.
Save runejuhl/339e886b05a5d970379c846f2678fe11 to your computer and use it in GitHub Desktop.
Simple function benchmark comparison
(defn time*
[fs iterations]
(map-indexed
(fn [idx f]
(let [t (with-out-str
(time
(run! f (range iterations))))]
{:idx idx
:f f
:time t}))
fs))
(time* [(fn [_]
(merge-with into
{:omg {:lol 12
:wat {:wooo 12}}}))
(fn [_]
(merge-with merge
{:omg {:lol 12
:wat {:wooo 12}}}))] 1e7)
;; => ({:idx 0,
;; :f #function[dev/eval76792/fn--76793],
;; :time "\"Elapsed time: 1751.630289 msecs\"\n"}
;; {:idx 1,
;; :f #function[dev/eval76792/fn--76795],
;; :time "\"Elapsed time: 1173.778828 msecs\"\n"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment