Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active March 8, 2018 01:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/765ac8e43d70b743e3bfbd02ff4703a1 to your computer and use it in GitHub Desktop.
Save mfikes/765ac8e43d70b743e3bfbd02ff4703a1 to your computer and use it in GitHub Desktop.
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