Skip to content

Commit

Permalink
added bench for writing html string first, then to outputstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 21, 2024
1 parent 1e4c5c4 commit 2a51646
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions dev/bench/chassis.clj
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,17 @@
(with-open [pout (java.io.OutputStreamWriter. out "UTF-8")]
(c/write-html pout [c/doctype-html5 (page-compiled-unambig data)]))
(.toByteArray out)))

(defn chassis-page-output-stream-writer-html-string
[data]
(let [out (java.io.ByteArrayOutputStream. 16384)]
(with-open [pout (java.io.OutputStreamWriter. out "UTF-8")]
(.write pout (c/html [c/doctype-html5 (page data)])))
(.toByteArray out)))

(defn chassis-page-output-stream-writer-html-string-compiled-unambig
[data]
(let [out (java.io.ByteArrayOutputStream. 16384)]
(with-open [pout (java.io.OutputStreamWriter. out "UTF-8")]
(.write pout (c/html [c/doctype-html5 (page-compiled-unambig data)])))
(.toByteArray out)))
16 changes: 14 additions & 2 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
chassis-page-print-stream
chassis-page-print-stream-compiled-unambig
chassis-page-output-stream-writer
chassis-page-output-stream-writer-compiled-unambig]]
chassis-page-output-stream-writer-compiled-unambig
chassis-page-output-stream-writer-html-string
chassis-page-output-stream-writer-html-string-compiled-unambig]]
[bench.hiccup
:refer [hiccup-page
hiccup-page-compiled
Expand Down Expand Up @@ -129,6 +131,14 @@
(println "Chassis OutputStreamWriter Compiled Unambig")
(println "-------------------------------------")
(bench (chassis-page-output-stream-writer-compiled-unambig data))
(println)
(println "Chassis OutputStreamWriter HTML String")
(println "-------------------------------------")
(bench (chassis-page-output-stream-writer data))
(println)
(println "Chassis OutputStreamWriter HTML String Compiled Unambig")
(println "-------------------------------------")
(bench (chassis-page-output-stream-writer-compiled-unambig data))
(println)))))

(defn gen-bench-hiccup
Expand Down Expand Up @@ -198,7 +208,9 @@
(slurp (chassis-page-print-stream data-small))
(slurp (chassis-page-print-stream-compiled-unambig data-small))
(slurp (chassis-page-output-stream-writer data-small))
(slurp (chassis-page-output-stream-writer-compiled-unambig data-small))))
(slurp (chassis-page-output-stream-writer-compiled-unambig data-small))
(slurp (chassis-page-output-stream-writer-html-string data-small))
(slurp (chassis-page-output-stream-writer-html-string-compiled-unambig data-small))))

(assert (= (hiccup-page data-small)
(hiccup-page-compiled data-small)
Expand Down
1 change: 1 addition & 0 deletions src/dev/onionpancakes/chassis/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

(defn html
"Returns HTML string given a HTML Node tree."
{:tag String}
[root]
(let [sb (StringBuilder. 16384)
_ (write-html sb root)]
Expand Down

0 comments on commit 2a51646

Please sign in to comment.