How long does Clojure start-up really take? Let’s find out.
Get yourself a Clojure project. Download the dependencies and pre-generate the classpath:
lein deps lein classpath > cp.txt
This lets us run “raw” Clojure, without any tooling. Assuming a Bash-like shell:
time java -cp "$(cat cp.txt)" clojure.main -e '(System/exit 0)'
Now add Leiningen:
time lein run -m clojure.main -e '(System/exit 0)'
Next, add the Leiningen REPL:
time lein repl <<< "(exit)"
If you’re a fan of Emacs and CIDER, start Emacs and paste this into a scratch buffer:
(require 'cider) (defvar cider-jack-in-start-time nil) (defun start-timing-cider-jack-in (&rest args) (setq cider-jack-in-start-time (current-time))) (defun elapsed-time-cider-jack-in (&rest args) (when cider-jack-in-start-time (prog1 (format "%.3f seconds" (float-time (time-since cider-jack-in-start-time))) (setq cider-jack-in-start-time nil)))) (add-function :before (symbol-function 'cider-jack-in) #'start-timing-cider-jack-in) (setq cider-connection-message-fn #'elapsed-time-cider-jack-in)
Evaluate that Elisp code with
M-x eval-buffer, then open up your
project.clj and run
Run each of these examples a few times to warm up the circuits.
How long does it take? On an empty project with just Clojure 1.8, I get:
|java -cp … clojure.main||0.8 seconds|
|lein run -m clojure.main||2.2 seconds|
|lein repl||4.2 seconds|
Yes, Clojure start-up could be faster, but make sure you know where the time is really going.
My environment: Leiningen 2.7.1, Oracle JDK 1.8.0_92, OS X