Groovy code gets faster and slower when using "@CompileStatic"

673 views Asked by At

I have the following snipet of Groovy code

class Test 
{
//  @groovy.transform.CompileStatic
    static main(args) 
    {
        long start = System.currentTimeMillis()
        def x = "3967"
        println x ==~ /[0-9]+([1379])$/
        println System.currentTimeMillis()-start
    }
}

Which is supposed to test weather x is a number ending in 1,3,7,or 9

I'm using the groovy plugin for eclipse, so when i want to run the code I have a few options, I can either run it as a Groovy Script, or as a Java application. Here are the runtimes.

Groovy Script: 93ms
Java Application: 125ms

But then when I enable Static compilation, this happens

Groovy Script: 0ms
Java Application: 312ms 

I'm confused,
1. I thought compiling to a Java application was supposed to be faster than running Groovy as a script.
2. Why is it that the Groovy script option gets so much faster with static compilation, and the Java one gets longer?

0

There are 0 answers