Package

Source Code of Groovy

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.MetaClass;
import groovy.lang.Script;

public class Groovy {

  /**
   * @param args
   */
  public static void main(final String[] args) {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    long start = System.currentTimeMillis();
    Script script = shell.parse("x = 123; return foo * 10");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    for (int i = 0; i < 1000; i++) {
      script.run();
    }
    long end = System.currentTimeMillis() - start;
    System.out.println("Parsowenie " + end);

    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
      Object value = shell.evaluate("x = 123; return foo * 10");
    }
    end = System.currentTimeMillis() - start;
    System.out.println("Evolution " + end);

    // assert value.equals(new Integer(20));
    // assert binding.getVariable("x").equals(new Integer(123));

  }
}
TOP

Related Classes of Groovy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.