From 7e850af84c9468b7ad505aac6937b46e061844c8 Mon Sep 17 00:00:00 2001 From: onionpancakes <639985+onionpancakes@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:42:29 -0800 Subject: [PATCH] refactored gen bench fns --- dev/bench/chassis.clj | 86 +++++++++++------- dev/user.clj | 196 ++++++++++++++++++++++++++---------------- 2 files changed, 176 insertions(+), 106 deletions(-) diff --git a/dev/bench/chassis.clj b/dev/bench/chassis.clj index 9665543..17fb96e 100644 --- a/dev/bench/chassis.clj +++ b/dev/bench/chassis.clj @@ -156,29 +156,6 @@ (doall))] [:footer "Footer"]]]) -(defn page-alias - [data] - [::Layout {::title (:title data)} - (->> (:items data) - (map #(vector ::Item {::item %})) - (interpose [:hr]))]) - -(defn page-alias-compiled - [data] - (cc/compile - [::LayoutCompiled {::title (:title data)} - (->> (:items data) - (map #(cc/compile [::ItemCompiled {::item %}])) - (interpose (cc/compile [:hr])))])) - -(defn page-alias-compiled-unambig - [data] - (cc/compile - [::LayoutCompiledUnambig {::title (:title data)} - (->> (:items data) - (map #(cc/compile [::ItemCompiledUnambig {::item %}])) - (interpose (cc/compile [:hr])))])) - (defn page-compiled [data] (cc/compile @@ -217,21 +194,34 @@ (interpose (cc/compile [:hr])))] [:footer "Footer"]]])) -(defn chassis-page +(defn page-alias [data] - (c/html [c/doctype-html5 (page data)])) + [::Layout {::title (:title data)} + (->> (:items data) + (map #(vector ::Item {::item %})) + (interpose [:hr]))]) -(defn chassis-page-alias +(defn page-alias-compiled [data] - (c/html [c/doctype-html5 (page-alias data)])) + (cc/compile + [::LayoutCompiled {::title (:title data)} + (->> (:items data) + (map #(cc/compile [::ItemCompiled {::item %}])) + (interpose (cc/compile [:hr])))])) -(defn chassis-page-alias-compiled +(defn page-alias-compiled-unambig [data] - (c/html [c/doctype-html5 (page-alias-compiled data)])) + (cc/compile + [::LayoutCompiledUnambig {::title (:title data)} + (->> (:items data) + (map #(cc/compile [::ItemCompiledUnambig {::item %}])) + (interpose (cc/compile [:hr])))])) -(defn chassis-page-alias-compiled-unambig +;; + +(defn chassis-page [data] - (c/html [c/doctype-html5 (page-alias-compiled-unambig data)])) + (c/html [c/doctype-html5 (page data)])) (defn chassis-page-compiled [data] @@ -241,6 +231,18 @@ [data] (c/html [c/doctype-html5 (page-compiled-unambig data)])) +(defn chassis-page-alias + [data] + (c/html [c/doctype-html5 (page-alias data)])) + +(defn chassis-page-alias-compiled + [data] + (c/html [c/doctype-html5 (page-alias-compiled data)])) + +(defn chassis-page-alias-compiled-unambig + [data] + (c/html [c/doctype-html5 (page-alias-compiled-unambig data)])) + (defn chassis-page-print-writer [data] (let [out (java.io.ByteArrayOutputStream. 16384) @@ -249,6 +251,14 @@ (c/write-html wtr [c/doctype-html5 (page data)])) out)) +(defn chassis-page-print-writer-compiled-unambig + [data] + (let [out (java.io.ByteArrayOutputStream. 16384) + charset (java.nio.charset.Charset/forName "UTF-8")] + (with-open [wtr (java.io.PrintWriter. out false charset)] + (c/write-html wtr [c/doctype-html5 (page-compiled-unambig data)])) + out)) + (defn chassis-page-print-stream [data] (let [out (java.io.ByteArrayOutputStream. 16384)] @@ -256,9 +266,23 @@ (c/write-html pout [c/doctype-html5 (page data)])) out)) +(defn chassis-page-print-stream-compiled-unambig + [data] + (let [out (java.io.ByteArrayOutputStream. 16384)] + (with-open [pout (java.io.PrintStream. out false "UTF-8")] + (c/write-html pout [c/doctype-html5 (page-compiled-unambig data)])) + out)) + (defn chassis-page-output-stream-writer [data] (let [out (java.io.ByteArrayOutputStream. 16384)] (with-open [pout (java.io.OutputStreamWriter. out "UTF-8")] (c/write-html pout [c/doctype-html5 (page data)])) out)) + +(defn chassis-page-output-stream-writer-compiled-unambig + [data] + (let [out (java.io.ByteArrayOutputStream. 16384)] + (with-open [pout (java.io.OutputStreamWriter. out "UTF-8")] + (c/write-html pout [c/doctype-html5 (page-compiled-unambig data)])) + out)) diff --git a/dev/user.clj b/dev/user.clj index 1658486..f1e8f2c 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -1,18 +1,28 @@ (ns user (:require [bench.chassis :refer [page + page-doall chassis-page - chassis-page-alias chassis-page-alias-compiled + chassis-page-compiled + chassis-page-compiled-unambig + chassis-page-alias + chassis-page-alias-compiled chassis-page-alias-compiled-unambig - chassis-page-compiled chassis-page-compiled-unambig - chassis-page-print-writer chassis-page-print-stream - chassis-page-output-stream-writer]] + chassis-page-print-writer + chassis-page-print-writer-compiled-unambig + chassis-page-print-stream + chassis-page-print-stream-compiled-unambig + chassis-page-output-stream-writer + chassis-page-output-stream-writer-compiled-unambig]] [bench.hiccup - :refer [hiccup-page hiccup-page-compiled + :refer [hiccup-page + hiccup-page-compiled hiccup-page-compiled-unambig]] - [bench.selmer :refer [selmer-page]] + [bench.selmer + :refer [selmer-page]] [bench.enlive - :refer [enlive-page-item-html enlive-page-item-template]] + :refer [enlive-page-item-html + enlive-page-item-template]] [dev.onionpancakes.chassis.core :as c] [dev.onionpancakes.chassis.compiler :as cc] [dev.onionpancakes.chassis.tests.test-core :as t] @@ -62,75 +72,111 @@ (def data-small (make-data 10)) -(defn quick-bench-all +(defn gen-bench-chassis [data] - (println "Chassis") - (println "-------------------------------------") - (quick-bench (chassis-page data)) - (println) - (println "Chassis alias") - (println "-------------------------------------") - (quick-bench (chassis-page-alias data)) - (println) - (println "Hiccup") - (println "-------------------------------------") - (quick-bench (hiccup-page data)) - (println) - (println "Hiccup runtime") - (println "-------------------------------------") - (quick-bench (hiccup-page-runtime data)) - (println) - (println "Selmer") - (println "-------------------------------------") - (quick-bench (selmer-page data)) - (println) - (println "Enlive item html") - (println "-------------------------------------") - (quick-bench (enlive-page-item-html data)) - (println) - (println "Enlive item template") - (println "-------------------------------------") - (quick-bench (enlive-page-item-template data))) + (let [file-name (str "resources/bench/chassis_" (count (:items data)) ".txt")] + (with-open [wtr (clojure.java.io/writer file-name)] + (binding [*out* wtr] + (println "Chassis") + (println "-------------------------------------") + (bench (chassis-page data)) + (println) + (println "Chassis Compiled") + (println "-------------------------------------") + (bench (chassis-page-compiled data)) + (println) + (println "Chassis Compiled Unambig") + (println "-------------------------------------") + (bench (chassis-page-compiled-unambig data)) + (println) + (println "Chassis Alias") + (println "-------------------------------------") + (bench (chassis-page-alias data)) + (println) + (println "Chassis Alias Compiled") + (println "-------------------------------------") + (bench (chassis-page-alias-compiled data)) + (println) + (println "Chassis Alias Compiled Unambig") + (println "-------------------------------------") + (bench (chassis-page-alias-compiled-unambig data)) + (println))))) -(defn bench-all +(defn gen-bench-chassis-write-html [data] - (println "Chassis") - (println "-------------------------------------") - (bench (chassis-page data)) - (println) - (println "Chassis alias") - (println "-------------------------------------") - (bench (chassis-page-alias data)) - (println) - (println "Hiccup") - (println "-------------------------------------") - (bench (hiccup-page data)) - (println) - (println "Hiccup runtime") - (println "-------------------------------------") - (bench (hiccup-page-runtime data)) - (println) - (println "Selmer") - (println "-------------------------------------") - (bench (selmer-page data)) - (println) - (println "Enlive item html") - (println "-------------------------------------") - (bench (enlive-page-item-html data)) - (println) - (println "Enlive item template") - (println "-------------------------------------") - (bench (enlive-page-item-template data))) + (let [file-name (str "resources/bench/chassis_write_html_" (count (:items data)) ".txt")] + (with-open [wtr (clojure.java.io/writer file-name)] + (binding [*out* wtr] + (println "Chassis PrintWriter") + (println "-------------------------------------") + (bench (chassis-page-print-writer data)) + (println) + (println "Chassis PrintWriter Compiled Unambig") + (println "-------------------------------------") + (bench (chassis-page-print-writer-compiled-unambig data)) + (println) + (println "Chassis PrintStream") + (println "-------------------------------------") + (bench (chassis-page-print-stream data)) + (println) + (println "Chassis PrintStream Compiled Unambig") + (println "-------------------------------------") + (bench (chassis-page-print-stream-compiled-unambig data)) + (println) + (println "Chassis OutputStreamWriter") + (println "-------------------------------------") + (bench (chassis-page-output-stream-writer data)) + (println) + (println "Chassis OutputStreamWriter Compiled Unambig") + (println "-------------------------------------") + (bench (chassis-page-output-stream-writer-compiled-unambig data)) + (println))))) -(defn bench-gen-results - ([] - (with-open [wtr (clojure.java.io/writer "resources/bench/results_big.txt")] - (binding [*out* wtr] - (bench-all data-big))) - (with-open [wtr (clojure.java.io/writer "resources/bench/results_mid.txt")] - (binding [*out* wtr] - (bench-all data-mid))) - (with-open [wtr (clojure.java.io/writer "resources/bench/results_small.txt")] - (binding [*out* wtr] - (bench-all data-small)))) - ([_] (bench-gen-results))) +(defn gen-bench-hiccup + [data] + (let [file-name (str "resources/bench/hiccup_" (count (:items data)) ".txt")] + (with-open [wtr (clojure.java.io/writer file-name)] + (binding [*out* wtr] + (println "Hiccup") + (println "-------------------------------------") + (bench (hiccup-page data)) + (println) + (println "Hiccup Compiled") + (println "-------------------------------------") + (bench (hiccup-page-compiled data)) + (println) + (println "Hiccup Compiled Unambig") + (println "-------------------------------------") + (bench (hiccup-page-compiled-unambig data)) + (println))))) + +(defn gen-bench-selmer + [data] + (let [file-name (str "resources/bench/selmer_" (count (:items data)) ".txt")] + (with-open [wtr (clojure.java.io/writer file-name)] + (binding [*out* wtr] + (println "Selmer") + (println "-------------------------------------") + (bench (selmer-page data)) + (println))))) + +(defn gen-bench-enlive + [data] + (let [file-name (str "resources/bench/enlive_" (count (:items data)) ".txt")] + (with-open [wtr (clojure.java.io/writer file-name)] + (binding [*out* wtr] + (println "Enlive Item HTML") + (println "-------------------------------------") + (bench (enlive-page-item-html data)) + (println) + (println "Enlive Item Template") + (println "-------------------------------------") + (bench (enlive-page-item-template data)) + (println))))) + +(defn gen-bench-all + [data] + (gen-bench-chassis data) + (gen-bench-hiccup data) + (gen-bench-selmer data) + (gen-bench-enlive data))