Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active January 3, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/8471718 to your computer and use it in GitHub Desktop.
Save cgrand/8471718 to your computer and use it in GitHub Desktop.
Generating a 5x5 table. (pr-str just dumps the 5*5 vector) In increasing order: pr-str (24.5µs), enlive N (24.8µs), hiccup (44.8µs), enlive (130µs), laser (1280µs).
=> (let [t (static-template
(enliven.html.jsoup/parse "<table><tr><td>#1")
"tr" (dup []
"td" (dup []
(content []))))
d (mapv vec (partition 5 (cons "<&>" (map str (range 25)))))
#_#_quick-bench prn
html "<html><head></head><body><table><tr><td>#1"
te (h/template (h/html-snippet html) [d]
[:tr] (h/clone-for [d d]
[:td] (h/clone-for [d d]
(h/content d))))
te (fn [d] (apply str (te d)))
li (l/parse "<html><head></head><body><table><tr><td>#1")
lt (fn [d]
(l/document li
(l/element= :tr)
(fn [tr]
(for [row d]
(l/at tr
(l/element= :td)
(fn [td]
(for [item row]
((l/content item) td))))))))
]
(println "Laser\n========")
(quick-bench (lt d))
(println "Enlive\n========")
(quick-bench (te d))
(println "Enlive N\n========")
(quick-bench (t d))
(println "\nhiccup\n======")
(quick-bench
(hiccup/html
[:html [:head]
[:body
[:table
[:tbody (for [row d]
[:tr (for [x row]
[:td (hiccup.util/escape-html x)])])]]]]))
(println "\npr-str\n======")
(quick-bench (pr-str d)))
Laser
========
WARNING: Final GC required 33.976993043185935 % of runtime
Evaluation count : 474 in 6 samples of 79 calls.
Execution time mean : 1,282831 ms
Execution time std-deviation : 24,302753 µs
Execution time lower quantile : 1,259618 ms ( 2,5%)
Execution time upper quantile : 1,320228 ms (97,5%)
Overhead used : 1,847192 ns
Enlive
========
WARNING: Final GC required 29.248431271610297 % of runtime
Evaluation count : 4800 in 6 samples of 800 calls.
Execution time mean : 129,545029 µs
Execution time std-deviation : 2,330201 µs
Execution time lower quantile : 127,561904 µs ( 2,5%)
Execution time upper quantile : 132,121279 µs (97,5%)
Overhead used : 1,847192 ns
Enlive N
========
WARNING: Final GC required 29.63475127348284 % of runtime
Evaluation count : 24822 in 6 samples of 4137 calls.
Execution time mean : 24,873103 µs
Execution time std-deviation : 462,508193 ns
Execution time lower quantile : 24,477969 µs ( 2,5%)
Execution time upper quantile : 25,396026 µs (97,5%)
Overhead used : 1,847192 ns
hiccup
======
WARNING: Final GC required 30.17932285745441 % of runtime
Evaluation count : 13674 in 6 samples of 2279 calls.
Execution time mean : 44,802161 µs
Execution time std-deviation : 1,305291 µs
Execution time lower quantile : 43,934968 µs ( 2,5%)
Execution time upper quantile : 47,066275 µs (97,5%)
Overhead used : 1,847192 ns
Found 1 outliers in 6 samples (16,6667 %)
low-severe 1 (16,6667 %)
Variance from outliers : 13,8889 % Variance is moderately inflated by outliers
pr-str
======
WARNING: Final GC required 29.233659257121808 % of runtime
Evaluation count : 25512 in 6 samples of 4252 calls.
Execution time mean : 24,528923 µs
Execution time std-deviation : 700,905055 ns
Execution time lower quantile : 23,963346 µs ( 2,5%)
Execution time upper quantile : 25,341756 µs (97,5%)
Overhead used : 1,847192 ns
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment