Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zh/47c7e4bde725cdceb8437c3604c9f499 to your computer and use it in GitHub Desktop.
Save zh/47c7e4bde725cdceb8437c3604c9f499 to your computer and use it in GitHub Desktop.
Fast Clojure hello world using GraalVM

Fast Clojure Hello World Using GraalVM On Mac

Performance

Version Command Time (seconds)
Java time java -jar target/fastclj-1.0-standalone.jar 1.354
GraalVM time ./fastclj-1.0-standalone 0.014

Details

lein new fastclj; cd fastclj

cat<<'END'>./project.clj
(defproject fastclj "1.0"
  :description "Fast hello world using GraalVM"
  :dependencies [[org.clojure/clojure "1.9.0"]]
  :main fastclj.core
  :aot  :all)
END

cat<<'END'>./src/fastclj/core.clj
(ns fastclj.core (:gen-class))
(defn -main [& args] (println "Hello world!"))
END

lein compile && lein uberjar

time java -jar target/fastclj-1.0-standalone.jar

wget https://github.com/oracle/graal/releases/download/vm-1.0.0-rc12/graalvm-ce-1.0.0-rc12-macos-amd64.tar.gz
tar zxvf graalvm-ce-1.0.0-rc12-macos-amd64.tar.gz

GRAAL_BIN="$PWD/graalvm-ce-1.0.0-rc12/Contents/Home/bin"
$GRAAL_BIN/native-image \
  -H:+ReportUnsupportedElementsAtRuntime \
  -J-Xmx3G -J-Xms3G --no-server \
  -jar target/fastclj-1.0-standalone.jar

ls -l ./fastclj-1.0-standalone

time ./fastclj-1.0-standalone 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment