Jasmine Expression Evaluator (Faster than Java)

You are probably looking at this because of the 'Faster than Java' tag line which is the truth but not the whole truth :) . To find out more read on.

Jasmine is a numerical expression and algorithm evaluator so in some respects it is similar to QScript. Although QScript is extremely versatile and extensible these are included at the expense of speed. Jasmine is fast, extremely fast, in fact faster that Java when evaluating expressions (although not as fast when evaluating algorithms)

The following code calculates the distance between 2 points and demonstrates how easy it is to use Jasmine.

String expr = "sqrt((x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1))";
Expression e = Compile.expression(expr, true);
System.out.println("Build time = " + e.getBuildTime() + " nanoseconds");
float d = e.eval(-5, 7, 4, 9).answer().toFloat();
System.out.println("Distance = " + d);
System.out.println("Eval time = " + e.getEvalTime() + " nanoseconds");

Most of the work is done in line 2 where the string expression is converted into an Expression object which is then used to evaluate the expression. Jasmine parses the expression and then uses the excellent ASM byte code manipulation library to convert it to Java byte code. This is similar to what the Java compiler does but does it at run time. Once compiled the expression can be evaluated as many times as we like, it is this evaluation (line 4) which is faster than Java.

Algorithms include conditional statements, loop constructs and support for variables.

You can install this library through the PDE Add Library option.

Want to know more then visit the website.


  • Impressive... And useful, as several people asked for such expression evaluator. You should include these two keywords in your subject, to ease searches...

  • edited December 2014

    Keywords tags added - thanks for the positive feedback

  • I will definately use this in the future.

    Is this some kind of follow-up of QScript or is it a faster but limited version? Because in QScript you can define your own operators and classes but apparently not in Jasmine. Will things like this be included in Jasmine or are they purposedly omitted to speed up evaluation time?

  • Although QScript and Jasmine both evaluate expressions and algorithms they are NOT related in any way.

    The power of Jasmine is its speed, it is thousands of times faster that QScript but to achieve that speed means that it is not possible to extend it by simply adding classes.

    For a third party to extend Jasmine they would need to have

    1) good knowledge of OO / Java

    2) basic knowledge of Java byte code instructions

    3) basic knowledge of Java class file structure (that's the compiled code not Java source code)

    4) how to use the ASM library to create Java byte code.

    to extend QScript you only needed (1)

    Given these restrictions it will not be possible to create an extensible Jasmine :{

    I must confess that I originally had no plans to create Jasmine. I discovered ASM over 12 months ago and I was intrigued with the idea of being able to modify compiler Java classes at run-time. ASM has a very steep learning curve and I must admit I couldn't get my head round it.

    A few months ago I revisited ASM and took the plunge and printed out the library guide for it (all 170 or so pages). I was interested in the idea of creating a profiling tool for Processing and thought ASM might be up to the task. Jasmine is the by-product of me trying to learn to program with ASM.

    I hope you enjoy using it, I am semi-seriously considering to use a modified version of it with G4P to create a simple spreadsheet control. :-?

  • Is it possible to loop over arrays? I tried, but no luck so far :)

    And if it's not possible, could you explain why?

  • Jasmine does not support arrays internally, which should answer both questions. :)

    It is possible to do a Jasmine evaluation inside a loop with different initial values, see the examples that come with the library and my website

  • Any plans for bit shifting?

    import org.quark.jasmine.*;

    void setup() {
       String lines[] = {
         "# first test",
         "red = c >> 16 & 0xFF"
       Algorithm a = Compile.algorithm(lines, false);
       a.eval("c", color(200,0,0));
  • I have no plans at present for new features for Jasmine. It will take a significant amount of effort to use data types other thandouble, bit shifting always operates on 32 bit integers. Also at the moment I am working on a steganography library for Processing.

  • Also at the moment I am working on a steganography library for Processing.

    Cool, image based I suppose?

  • Yes it uses an image for the 'carrier' and the 'burden' can be either another image or text. The user supplies a password/pass phrase which is used to encrpt the burden before integrating into the carrier image. The software looks at the carrier and the burden then determines how best to integrate burden to minimise the effect on the carrier image. Just a bit of fun really.

  • You need a tester? :) I would love to try that out. Now we finally have a way to get porn in the app store :)

  • @clankill3r send me a PM with your email address.

Sign In or Register to comment.