Skip to content

Instantly share code, notes, and snippets.

@mfikes

mfikes/README.md

Last active Mar 8, 2018
Embed
What would you like to do?
Browser REPL stress test

Run the test.clj below in a Clojure REPL, adjusting the cmd vector as needed to launch things.

It will launch the browser REPL and imitate a user typing forms into it. (If you don't have Safari set as your default browser, you can splice ["-ro" "{:launch-browser false}" "-r"] into the end of the cmd vector and launch Safari manually, pointing it at http://localhost:9000

In your browser open the JavaScript console to see progress.

A faster verzion, zippy.clj eliminates the JavaScript console logging and the Thread/sleep calls, evaluating the sequence of integer forms as quickly as possible.

To instead compare with Figwheel, do

lein new figwheel test

Then cd into test and run the program below, but changing cmd to be ["lein" "figwheel"].

(require '[clojure.java.io :as io])
(let [cmd ["clj" "-A:cljs"]
proc (.exec (Runtime/getRuntime) (into-array cmd))
out (.getInputStream proc)
err (.getErrorStream proc)
in (.getOutputStream proc)]
(future (io/copy out *out*))
(future (io/copy err *err*))
(loop [n 0]
(io/copy (io/input-stream (.getBytes (str "(inc " n ")\n"))) in)
(io/copy (io/input-stream (.getBytes (str "(.log js/console " n ")\n"))) in)
(.flush in)
(Thread/sleep (+ 100 (rand-int 200)))
(recur (inc n))))
(require '[clojure.java.io :as io])
(let [cmd ["clj" "-A:cljs"]
proc (.exec (Runtime/getRuntime) (into-array cmd))
out (.getInputStream proc)
err (.getErrorStream proc)
in (.getOutputStream proc)]
(future (io/copy out *out*))
(future (io/copy err *err*))
(loop [n 0]
(io/copy (io/input-stream (.getBytes (str "(inc " n ")\n"))) in)
(.flush in)
(recur (inc n))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment