Skip to content

Instantly share code, notes, and snippets.

@whilo
Created May 21, 2014 22:09
Show Gist options
  • Save whilo/b08062def8af92829876 to your computer and use it in GitHub Desktop.
Save whilo/b08062def8af92829876 to your computer and use it in GitHub Desktop.
(ns cljc.play)
(defn fib [x]
(if (or (= x 1) (= x 0)) 1
(+ (fib (- x 1)) (fib (- x 2)))))
(fib 30)
(defn msec []
(c* "#include <sys/time.h>")
(c* "struct timeval tv")
(c* "gettimeofday(&tv, NULL)")
(c* "make_integer( tv.tv_sec * 1000 + tv.tv_usec / 1000 )"))
(do
(let [start (msec)
res (fib 30)
end (msec)]
(println "Duration: " (- end start) "ms, result:" res)))
(defn fibc [x]
(c* "int fibc(int x) { if(x == 0 || x == 1) {return 1;} else {return fibc(x-1) + fibc(x-2);}}")
(c* "make_integer( fibc( integer_get( ~{} ) ) );" x))
(fibc 30)
(do
(let [start (msec)
res (fibc 30)
end (msec)]
(println "Duration: " (- end start) "ms, result:" res)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment