Skip to content

Instantly share code, notes, and snippets.

@w01fe
Forked from hiredman/lexicaltest.clj
Created June 13, 2011 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save w01fe/1023816 to your computer and use it in GitHub Desktop.
Save w01fe/1023816 to your computer and use it in GitHub Desktop.
(def fib-var-obj
(fn [x]
(if (< x 2)
1
(+ (fib-var-obj (- x 1))
(fib-var-obj (- x 2))))))
(defn fib-lex-obj [x]
(if (< x 2)
1
(+ (fib-lex-obj (- x 1))
(fib-lex-obj (- x 2)))))
(def fib-var-prim
(fn ^long [^long x]
(if (< x 2)
1
(+ (fib-var-prim (- x 1))
(fib-var-prim (- x 2))))))
(defn fib-lex-prim ^long [^long x]
(if (< x 2)
1
(+ (fib-lex-prim (- x 1))
(fib-lex-prim (- x 2)))))
(dotimes [i 3]
(println "\nRun" i)
(doseq [[n f] [["var-obj" fib-var-obj]
["lex-obj" fib-lex-obj]
["var-prim" fib-var-prim]
["lex-prim" fib-lex-prim]]]
(print n "result, time: ")
(time (print (f 35) ","))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment