$ time java -jar clojure-1.4.0.jar -e '(println "Hello world")'
Hello world
real 0m4.586s
$ time python clojure.py -c '(py/print "Hello world")'
real 0m14.690s
$ time mono Clojure.Main.exe -e '(println "hello world")'
hello world
real 0m4.843s
/* clojure-metal is not tested due to not being written at the moment */
Can Clojure startup time be little, as like when I run Perl or Python scripts? Is slow startup time an underlying framework's or Clojure's issue (which can be fixed sooner or later) or it is by design?
Note: I already know about start-persistent-server-than-connect-to-it workaround.
ClojureScript can startup pretty quick. The number is a little misleading though because it does dead code removal when compiling. That means this snippet gets compiled down to just print("hello world");
. Here's what I get on my machine:
$ echo '(js/print "hello world")' > hello.cljs
$ cljsc hello.cljs '{:optimizations :advanced}' > hello.js
$ time rhino hello.js
hello world
real 0m0.466s
For comparison, here's what I get using normal clojure:
$ time java -jar clojure-1.4.0.jar -e '(println "hello world")'
hello world
real 0m1.369s
The startup time is mostly because of the work that Clojure itself does in terms of initialisation. Some of these tasks are quite significant, e.g. loading and compiling the core Clojure namespaces. Running on different platform implementations won't really change this.
However, there is a big potential for this to be optimised in the future:
Note that although the JVM is often (unjustly) blamed, the JVM is largely irrelevant here: modern JVMs have a startup time of about 0.1secs.
I actually exploit this for GUI apps written in Clojure: by writing the startup code in pure Java with a main
method, you can have a splash screen and first screen of your GUI appear pretty much immediately, and then load Clojure along with the rest of your application code in the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With