forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace whiteboard printing with ugly print
Prints fast with newlines clojure -M:test:bench Testing frontend.benchmark-test-runner [], (with-out-str (pprint/pprint onboarding)), 10 runs, 2950 msecs [], (with-out-str (fipp/pprint onboarding)), 10 runs, 2447 msecs [], (up/ugly-pr-str onboarding), 10 runs, 94 msecs [], (pr-str onboarding), 10 runs, 82 msecs
- Loading branch information
1 parent
03afc90
commit 3b6a89c
Showing
6 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ pom.xml.asc | |
node_modules/ | ||
static/ | ||
tmp | ||
cljs-test-runner-out | ||
|
||
.cpcache/ | ||
/src/gen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(ns frontend.benchmark-test-runner | ||
"Runs a benchmark" | ||
(:require [clojure.edn :as edn] | ||
[frontend.macros :refer [slurped]] | ||
[frontend.modules.file.uprint :as up] | ||
[clojure.pprint :as pprint] | ||
[clojure.test :refer [run-tests deftest testing]] | ||
[fipp.edn :as fipp])) | ||
|
||
(def onboarding | ||
(edn/read-string (slurped "resources/whiteboard/onboarding.edn"))) | ||
|
||
(deftest test-pp-str | ||
(testing "pp-str benchmark" | ||
(simple-benchmark [] | ||
(with-out-str (pprint/pprint onboarding)) | ||
10) | ||
(simple-benchmark [] | ||
(with-out-str (fipp/pprint onboarding)) | ||
10) | ||
(simple-benchmark [] | ||
(up/ugly-pr-str onboarding) | ||
10) | ||
(simple-benchmark [] | ||
(pr-str onboarding) | ||
10) | ||
;; uncomment to see the output | ||
#_(println (up/ugly-pr-str onboarding)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(ns frontend.macros | ||
#?(:cljs (:require-macros [frontend.macros]) | ||
:clj (:require [clojure.edn :as edn]))) | ||
|
||
#?(:clj | ||
(defmacro slurped | ||
"Like slurp, but at compile time" | ||
[filename] | ||
(slurp filename))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns frontend.modules.file.uprint) | ||
|
||
(defn print-prefix-map* [prefix m print-one writer opts] | ||
(pr-sequential-writer | ||
writer | ||
(fn [e w opts] | ||
(do (print-one (key e) w opts) | ||
(-write w \space) | ||
(print-one (val e) w opts))) | ||
(str prefix "{") \newline "}" | ||
opts (seq m))) | ||
|
||
(defn ugly-pr-str | ||
"Ugly printing fast, with newline per block" | ||
[x] | ||
(with-redefs [print-prefix-map print-prefix-map*] | ||
(pr-str x))) |