Skip to content

Instantly share code, notes, and snippets.

@puredanger
Created November 13, 2012 03:25
Show Gist options
  • Save puredanger/4063756 to your computer and use it in GitHub Desktop.
Save puredanger/4063756 to your computer and use it in GitHub Desktop.
benchmark code
(ns x
(:use [criterium.core]))
(defn pre-into [c i]
(into [i] c))
(defn dl
"Return a difference list for a list"
[l]
(fn [x] (concat l x)))
; Return an empty difference list
(def dlempty identity)
(defn undl
"Return a list for a difference list (just call the difference list with nil)"
[aDl]
(aDl nil))
(defn dlcons
"Cons an item onto a difference list"
[item aDl]
(fn [x] (cons item (aDl x))))
(defn dlappend
"Append two difference lists"
[dl1 dl2]
(fn [x] (dl1 (dl2 x))))
(defn pre-dl [c i]
(dlappend (dl (list i)) c))
(defn do-test [init f post]
(doall (post (reduce f init (range 1000)))))
(defn test []
(with-progress-reporting (bench (do-test [] pre-into identity)))
(with-progress-reporting (bench (do-test (dl '()) pre-dl undl))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment