Skip to content

Instantly share code, notes, and snippets.

@skuro
Created January 20, 2011 22:35
Show Gist options
  • Save skuro/788834 to your computer and use it in GitHub Desktop.
Save skuro/788834 to your computer and use it in GitHub Desktop.
Simple functions to assess clojure perf
(ns skuro.tak
"Yet another clj1.3 perf test, this time as in http://bit.ly/fzrv6N.")
(defn tak ^long [^long x ^long y ^long z]
(if (>= y x)
z
(recur (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(time (dotimes [_ 1000] (tak 24 16 8)))
public class Tak {
static Integer tak (Integer x, Integer y, Integer z) {
if (y >= x) {
return z;
}
return tak (tak (x - 1, y, z), tak (y - 1, z, x), tak (z - 1, x, y));
}
public static void main (String[] args) {
long begin = System.currentTimeMillis();
for (int i = 0 ; i < 1000 ; i++) {
tak (24, 16, 8);
}
long end = System.currentTimeMillis();
System.out.println (String.format("Java execution took %s millis", end - begin));
}
}
(ns skuro.tak
"Yet another clj1.2 perf test, this time as in http://bit.ly/fzrv6N.")
(defn tak [#^Integer x #^Integer y #^Integer z]
(if (>= y x)
z
(recur (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(time (dotimes [_ 1000] (tak 24 16 8)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment