From b0069ac3720785457058e8f8ce1ce75818607bd1 Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Fri, 19 Jul 2013 13:57:04 -0700 Subject: [PATCH] added clj-mustache, new results --- README.md | 82 ++++++++++++------------ project.clj | 16 ++--- src/clojure_template_benchmarks/core.clj | 23 ++++++- 3 files changed, 69 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index f1bda22..b6323d3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Test results are avg / standard deviation. ## Data -Units are in microseconds (us) +The unit 'us' is microseconds. Typical bullshit "ran this on my macbook" arrangement. Run it on your own thing if you care. @@ -19,91 +19,91 @@ Units are in microseconds (us) - - - + + + - - - + + + - + Identical to or slower than non-type-hinted hiccup. + - - - + + + - - - + + + - - - + + + - - - + + + + + + + + + + - - - + + + - - - + + + - - - + + + - - - + + +
str0.165 us / 0.016 us14 us / 0.253 us273 us / 14 us0.365 us / 0.002 us29 us / 0.220 us572 us / 2 us
hiccup20 us / 0.367 us1100 us / 59 us24,000 us / 2900 us0.673 us / 0.006 us35 us / 1 us682 us / 3 us
hiccup (type-hinted)0.335 us / 0.013 us
clabango (string)329 us / 5.7 us1800 us / 146 us20,600 us / 799 us544 us / 6.7 us2452 us / 17 us30,000 us / 193 us
clabango (files)478 us / 42 us1,790 us / 52 us19,900 us / 573 us665 us / 8.7 us2,617 us / 22 us30,450 us / 390 us
stencil (string)58 us / 6 us212 us / 27 us930 us / 37 us90 us / 0.5 us290 us / 2.7 us1,300 us / 13 us
stencil (file)1.2 us / 0.022 us38 us / 0.943 us784 us / 16 us2.2 us / 0.019 us58 us / 0.465 us1,148 us / 10 us
mustache.clj (file)0.947 us / 0.006 us26 us / 0.206 us541 us / 4.7 us
tinsel23.7 us / 5.5 us1,100 us / 52 us22,000 us / 770 us0.678 us / 0.006 us34 us / 0.175 us679 us / 7.1 us
laser73.6 us / 1.5 us243 us / 18 us3,400 us / 61 us404 us / 9.4 us3,770 us / 26 us68,000 us / 925 us
laser (type-hinted)73.2 us / 3.0 us220 us / 21 us3,090 us / 101 us401 us / 3.1 us3,764 us / 18 us69,408 us / 1,028 us
enlive38 us / 0.435 us320 us / 10 us6,400 us / 450 us47 us / 0.397 us385 us / 8.5 us6,800 us / 51 us
## Conclusions -+ 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. -+ Enlive and Laser are faster than Hiccup and Clabango -+ Hiccup benefits greatly from type-hinting and comes close to str - Copyright © 2013 bitemyapp diff --git a/project.clj b/project.clj index dd72693..fada044 100644 --- a/project.clj +++ b/project.clj @@ -4,12 +4,12 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :main clojure-template-benchmarks.core - :dependencies [[org.clojure/clojure "1.4.0"] - [clabango "0.4"] - [criterium "0.3.1"] - [enlive "1.0.0"] - [hiccup "1.0.2"] - [stencil "0.3.0"] + :dependencies [[org.clojure/clojure "1.5.1"] + [clabango "0.5"] + [criterium "0.4.1"] ; 0.3.1 + [enlive "1.1.1"] + [hiccup "1.0.3"] + [stencil "0.3.2"] [tinsel "0.4.0" :exclusions [hickory]] - [me.raynes/laser "0.1.21"] - [enlive "1.0.1"]]) \ No newline at end of file + [me.raynes/laser "1.1.1"] + [me.shenfeng/mustache "1.1"]]) diff --git a/src/clojure_template_benchmarks/core.clj b/src/clojure_template_benchmarks/core.clj index 448b782..e52e017 100644 --- a/src/clojure_template_benchmarks/core.clj +++ b/src/clojure_template_benchmarks/core.clj @@ -5,7 +5,8 @@ [stencil.core :as stencil] [hiccup.core :as hiccup] [me.raynes.laser :as laser :refer [defdocument]] - [net.cgrand.enlive-html :as enlive])) + [net.cgrand.enlive-html :as enlive] + [me.shenfeng.mustache :as mustache])) (def bar (str "bar")) @@ -64,6 +65,14 @@ (defn list-stencil [ceil] (stencil/render-file "clojure_template_benchmarks/templates/list.mustache" {:items (range 1 ceil)})) +(mustache/deftemplate simple-mst (slurp "src/clojure_template_benchmarks/templates/simple.mustache")) +(mustache/deftemplate list-mst (slurp "src/clojure_template_benchmarks/templates/list.mustache")) + +(defn simple-mustache [] + (simple-mst {:bar bar})) + +(defn list-mustache [ceil] + (list-mst {:items (range 1 ceil)})) (deftemplate simple-tinsel [[:span {:class "foo"}]] [] (has-class? "foo") (set-content bar)) (deftemplate list-tinsel [[:ul]] [ceil] (tag= :ul) (set-content (for [x (range 1 ceil)] [:li x]))) @@ -71,14 +80,14 @@ (defdocument simple-laser "" [] (laser/class= "foo") (laser/content bar)) (defdocument list-laser "" [ceil] - (laser/element= :ul) (laser/html-content + (laser/element= :ul) (laser/content (for [x (range 1 ceil)] (laser/node :li :content (str x))))) (defdocument simple-laser-hinted "" [] (laser/class= "foo") (laser/content ^String bar)) (defdocument list-laser-hinted "" [ceil] - (laser/element= :ul) (laser/html-content + (laser/element= :ul) (laser/content (for [x (range 1 ceil)] (laser/node :li :content (str ^Number x))))) @@ -153,6 +162,14 @@ (with-progress-reporting (quick-bench (list-stencil 1000))) (println "\n --- \n") + (println "\n\n ***** mustache file ***** \n\n") + (with-progress-reporting (quick-bench (simple-mustache))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-mustache 50))) + (println "\n --- \n") + (with-progress-reporting (quick-bench (list-mustache 1000))) + (println "\n --- \n") + (println "\n\n ***** tinsel ***** \n\n") (with-progress-reporting (quick-bench (simple-tinsel))) (println "\n --- \n")