added stencil

This commit is contained in:
Chris Allen 2013-01-29 23:50:49 -08:00
parent 8acdd52a7a
commit 3909b08525
6 changed files with 51 additions and 3 deletions

View file

@ -37,6 +37,18 @@ Test results are avg / standard deviation.
<td>1.79 ms / 52 us</td>
<td>19.9 ms / 573 us</td>
</tr>
<tr>
<td>stencil (string)</td>
<td>58 us / 6 us</td>
<td>212 us / 27 us</td>
<td>930 us / 37 us</td>
</tr>
<tr>
<td>stencil (file)</td>
<td>1.2 us / 22 us</td>
<td>38 us / 943 ns</td>
<td>784 us / 16 us</td>
</tr>
</table>
@ -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

View file

@ -8,4 +8,5 @@
[criterium "0.3.1"]
[hiccup "1.0.2"]
[clabango "0.4"]
[stencil "0.3.0"]
])

View file

@ -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 "<span class=\"foo\">{{bar}}</span>" {:bar bar}))
(defn list-stencil-no-fd [ceil]
(stencil/render-string "<ul>{{#items}}<li>{{.}}</li>{{/items}}</ul>" {: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"))

View file

@ -0,0 +1 @@
<ul>{{#items}}<li>{{.}}</li>{{/items}}</ul>

View file

@ -1 +1 @@
<span class="foo">{{bar}}</span>
<span class="foo">{{bar}}</span>

View file

@ -0,0 +1 @@
<span class="foo">{{bar}}</span>