- Install graalvm.
sdk install java 22.3.r19-grl
- Change current JVM to graalvm.
sdk use java 22.3.r19-grl
- Install Graal js following the guide.
gu install js
- Create sample javascript files. Note that to use javascript modules, the files have to be with
mjs
suffix.
- foo.mjs
- main.mjs
- Run the javascript code.
js main.mjs
Let's do a simple benchmark to see how it performs. The benchmark is inspired by this one.
- Run
fib.js
.
time js fib.js
js fib.js 0.32s user 0.06s system 125% cpu 0.303 total
- Run
fib.py
.
time python fib.py
python fib.py 4.34s user 0.03s system 99% cpu 4.409 total
Even for such a simple function, Graal Javascript performs more than 10 times faster than the mature Python interpreter. How amazing it is!.