Created
January 20, 2011 22:35
-
-
Save skuro/788834 to your computer and use it in GitHub Desktop.
Simple functions to assess clojure perf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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