Skip to content

Commit

Permalink
simple benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
shenfeng committed Jul 11, 2012
1 parent 56ace11 commit 506fec7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion project.clj
@@ -1,10 +1,11 @@
(defproject me.shenfeng/mustache "0.0.3"
(defproject me.shenfeng/mustache "0.0.4"
:description "Mustache write in java, for clojure"
:dependencies [[clojure "1.4.0"]]
:warn-on-reflection true
:java-source-path "src/java"
:javac-options {:source "1.6" :target "1.6" :debug "true" :fork "true"}
:dev-dependencies [[swank-clojure "1.4.0"]
[junit/junit "4.8.2"]
[stencil "0.2.0"]
[de.ubercode.clostache/clostache "1.3.0"]])

49 changes: 49 additions & 0 deletions test/me/shenfeng/perf_bench.clj
@@ -0,0 +1,49 @@
(ns me.shenfeng.perf-bench
(:use me.shenfeng.mustache
stencil.core)
(:require [stencil.loader]))

(def template-str "
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<ul>
{{#list}}<li>id: {{id}}, name: {{name}}</li>
{{/list}}
</ul>
</body>
</html>
")

(deftemplate template template-str)

(def data {:title "mustache clojure implementation"
:list (concat [{:id "https://github.com/davidsantiago/stencil"
:name "stencil"}
{:id "https://github.com/shenfeng/mustache.clj"
:name "shenfeng"}]
(map (fn [id]
{:id id
:name (str "test-test" id)}) (range 1 10)))})

(stencil.loader/register-template "hithere" template-str)

(defn bench [&{:keys [loops] :or {loops 100000}}]
(println "warn up jvm")
(dotimes [i loops]
(to-html template data)
(render-file "hithere" data))

(println "bench stencil")
;; from a test run 6671.472264 msecs
(time (dotimes [i loops]
(render-file "hithere" data)))

;; from a tes run 625.272019 msecs
(println "bench mustache.clj")
(time (dotimes [i loops]
;; bench mustache.clj
(to-html template data))))

0 comments on commit 506fec7

Please sign in to comment.