Very Quick Java(X) Evaluation

I want Java to be like a scripting language — that is, able to evaluate any string of code at any time, and preferably really fast. The dream is now real.

// JavaX code to evaluate
S code = "sqrt(2)";

// turn optimizations on
transpileRaw_useDiskCache = true;
veryQuickJava_useCompilerBot = true;
setOpt(startBotHere("Compiler Bot", "#1002203"), "verbose", false);

// evaluate ten times
for i to 10: time { print(evalJava(code)); }

The dynamic code you see — ”sqrt(2)” — is a JavaX expression, that is, Java extended with over 2,000 standard functions and new short syntax.

The expression is translated to Java and compiled only the first time — every time after that it’s just loading a class and running it. Here are the timed results:

Compiling 691 chars
main java: /home/stefan/.javax/1479568538809/main.java
Compiler said:
Zipping: /home/stefan/.javax/1479568538810 to /home/stefan/JavaX-Caches/#1002203/d550a706502a40a7aafb89993ffce266.jar
Copying main.class
Copying main.java
Files zipped: 2
1.4142135623730951
2165 ms
Getting classes from cache (/home/stefan/JavaX-Caches/#1002203/d550a706502a40a7aafb89993ffce266.jar, 782 bytes)
1.4142135623730951
16 ms
Getting classes from cache (/home/stefan/JavaX-Caches/#1002203/d550a706502a40a7aafb89993ffce266.jar, 782 bytes)
1.4142135623730951
18 ms
Getting classes from cache (/home/stefan/JavaX-Caches/#1002203/d550a706502a40a7aafb89993ffce266.jar, 782 bytes)
1.4142135623730951
13 ms
[... equally fast from here on ...]

I’d say <20 ms is pretty decent and possibly even faster than eval() in some scripting languages. And you get the advantage of full Java speed in the actual code that is run!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.