diff --git a/README.md b/README.md index f1f2545..eeadb19 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,18 @@ Test results are avg / standard deviation. 1.79 ms / 52 us 19.9 ms / 573 us + + stencil (string) + 58 us / 6 us + 212 us / 27 us + 930 us / 37 us + + + stencil (file) + 1.2 us / 22 us + 38 us / 943 ns + 784 us / 16 us + @@ -45,5 +57,7 @@ Test results are avg / standard deviation. + str is really fast and a huge waste of programmer time. + clabango from filesystem templates or string literals are equivalent + clabango and hiccup are equivalent in performance ++ stencil from string literals is faster than clabango and hiccup, ++ stencil from files is even faster by a marginal amount. Copyright © 2013 bitemyapp diff --git a/project.clj b/project.clj index 2e2a542..a3da69e 100644 --- a/project.clj +++ b/project.clj @@ -8,4 +8,5 @@ [criterium "0.3.1"] [hiccup "1.0.2"] [clabango "0.4"] + [stencil "0.3.0"] ]) diff --git a/src/clojure_template_benchmarks/core.clj b/src/clojure_template_benchmarks/core.clj index 12edaab..9862924 100644 --- a/src/clojure_template_benchmarks/core.clj +++ b/src/clojure_template_benchmarks/core.clj @@ -1,7 +1,8 @@ (ns clojure-template-benchmarks.core (:use criterium.core hiccup.core) - (:require [clabango.parser :refer [render render-file]])) + (:require [clabango.parser :refer [render render-file]] + [stencil.core :as stencil])) (def bar (str "bar")) @@ -40,6 +41,20 @@ (render-file "clojure_template_benchmarks/templates/list.html" {:items (range 1 ceil)})) +(defn simple-stencil-no-fd [] + (stencil/render-string "{{bar}}" {:bar bar})) + +(defn list-stencil-no-fd [ceil] + (stencil/render-string "" {:items (range 1 ceil)})) + + +(defn simple-stencil [] + (stencil/render-file "clojure_template_benchmarks/templates/simple.mustache" {:bar bar})) + +(defn list-stencil [ceil] + (stencil/render-file "clojure_template_benchmarks/templates/list.mustache" {:items (range 1 ceil)})) + + (defn -main [& args] ;; (println (simple-hiccup)) ;; (println (simple-clabango-no-fd)) @@ -62,7 +77,7 @@ (with-progress-reporting (quick-bench (list-hiccup 1000))) (println "\n --- \n") - (println "\n\n ***** clabango string literals ***** \n\n") + (println "\n\n ***** clabango string ***** \n\n") (quick-bench (simple-clabango-no-fd)) (println "\n --- \n") (quick-bench (list-clabango-no-fd 50)) @@ -76,4 +91,20 @@ (with-progress-reporting (quick-bench (list-clabango 50))) (println "\n --- \n") (with-progress-reporting (quick-bench (list-clabango 1000))) + (println "\n --- \n") + + (println "\n\n ***** stencil string ***** \n\n") + (with-progress-reporting (quick-bench (simple-stencil-no-fd))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-stencil-no-fd 50))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-stencil-no-fd 1000))) + (println "\n --- \n") + + (println "\n\n ***** stencil file ***** \n\n") + (with-progress-reporting (quick-bench (simple-stencil))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-stencil 50))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-stencil 1000))) (println "\n --- \n")) diff --git a/src/clojure_template_benchmarks/templates/list.mustache b/src/clojure_template_benchmarks/templates/list.mustache new file mode 100644 index 0000000..b131a51 --- /dev/null +++ b/src/clojure_template_benchmarks/templates/list.mustache @@ -0,0 +1 @@ + diff --git a/src/clojure_template_benchmarks/templates/simple.html b/src/clojure_template_benchmarks/templates/simple.html index 67c4b3d..6b1d82a 100644 --- a/src/clojure_template_benchmarks/templates/simple.html +++ b/src/clojure_template_benchmarks/templates/simple.html @@ -1 +1 @@ -{{bar}} \ No newline at end of file +{{bar}} diff --git a/src/clojure_template_benchmarks/templates/simple.mustache b/src/clojure_template_benchmarks/templates/simple.mustache new file mode 100644 index 0000000..6b1d82a --- /dev/null +++ b/src/clojure_template_benchmarks/templates/simple.mustache @@ -0,0 +1 @@ +{{bar}}