Question

I'm developing some modelling software in C# which relies heavily on compiled mathematical statements. They are built at runtime using Linq Expressions giving me native performance. Performance is critical as formulas are run billions of times.

Longer term I'm considering moving the project to Java. However Java doesn't seem to have an equivalent library.

What options can the Java platform provide for compiling mathematical statements at run-time & getting native performance?

(P.S. apparently Java 8 will support lambda expressions, but I doubt the framework be as advanced as Linq.Expressions)

No correct solution

OTHER TIPS

One way to do this is to compile a Java class for each different expression, with a single static method that implements the function. See this question.

So, for example, if all your functions just use one variable x, then you could generate a .java file looking like this...

class Expression {
   static double apply(double x) {
       return /* expression here */;
   }
}

Then compile and load that class as in the cited question, get the apply() method with reflection, and call it whenever you want to compute that expression. (Alternately, have your compiled classes implement an interface, create instances of them, and avoid the reflection)

Admittedly, this is not particularly friendly to your memory usage if you end up with thousands of such classes...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top