Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(ns foo.core
[clostache.parser :as clostache]
[cuma.core :as cuma]))
(def MAX_NUM 10000)
(defmacro time*
`(let [start# (. System (nanoTime))
ret# ~expr]
[(/ (double (- (. System (nanoTime)) start#)) 1000000.0) ret#]))
(defmacro mytime [body]
`(print (str (first (time* (dotimes [n# MAX_NUM] ~body))) "\t")))
;`(println (str (identity (time* ~body)))))
(defn -main []
;;; cuma
(mytime (cuma/render "$(raw x)" {:x "<h1>"}))
(mytime (cuma/render "$(x)" {:x "<h1>"}))
(mytime (cuma/render "$(x.y)" {:x {:y "hello"}}))
(mytime (cuma/render "@(if x)hello@(end)" {:x true}))
(mytime (cuma/render "@(for arr)$(n)@(end)" {:arr [{:n 1} {:n 2} {:n 3}]}))
(mytime (cuma/render "@(if m)$(n)@(end)" {:m {:n 100}}))
(mytime (cuma/render "$(include tmpl)" {:tmpl "hello $(x)" :x "world"}))
(mytime (cuma/render "@(let :x \"foo\")$(x)@(end)" {}))
;;; clostache
(mytime (clostache/render "{{&x}}" {:x "<h1>"}))
(mytime (clostache/render "{{x}}" {:x "<h1>"}))
(mytime (clostache/render "{{&x.y}}" {:x {:y "hello"}}))
(mytime (clostache/render "{{#x}}hello{{/x}}" {:x true}))
(mytime (clostache/render "{{#arr}}{{n}}{{/arr}}" {:arr [{:n 1} {:n 2} {:n 3}]}))
(mytime (clostache/render "{{#m}}{{n}}{{/m}}" {:m {:n 100}}))
(mytime (clostache/render "{{>tmpl}}" {:x "world"} {:tmpl "hello {{x}}"}))
(print "\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment