package curveJudge import groovy.text.SimpleTemplateEngine /** * Created by Jxy on 2019/8/26 17:16 * */ class EngineTest { static void main(String[] args) { def shell = new GroovyShell() def engine = new SimpleTemplateEngine() def map = [ 'eg1' : 1, 'eg2' : 1, 'eg3' : 1, 'eg5' : 1, 'eg6' : 1, 'eg7': 1 , 'eg8': 1 , 'eg9': 1 , 'eg10': 1 , 'eg11': 1 , 'eg12': 1 , 'eg14': 1 , 'eg13': 1 , 'eg15 ': 1 , ' eg16 ': 1 , ' eg17 ': 1 , ' eg18 ': 1 , ' eg19 ': 1 , ' eg20 ': 1 , ' eg21 ': 1 , ' eg22 ':1 , 'Eg23': 1 , 'eg24': 1 , 'eg25': 1 , 'eg26': 1 , 'eg27': 1 , 'eg28': 1 , 'eg29': 1 , 'eg30': 1 , 'eg31': 1 , 'eg32 ': 1 , ' eg33 ': 1 , ' eg34 ': 1 , ' eg35 ': 1 , ' eg36 ': 1 , ' eg37 ': 1 , ' eg38 ': 1 , ' eg39 ':1 , ', eg40',: 1 , 'EG41':. 1 , 'eg42':. 1 , 'eg43':. 1 , 'eg44':. 1 , 'eg45':. 1 , ] DEF A = System.currentTimeMillis () String STR = '($ + $ EG10 EG1) * . 6 ' DEF string1 = engine.createTemplate (STR) .make (Map) .toString () the println "execution result: {$ -> shell.evaluate (string1)}" DEF B = System.currentTimeMillis () the println "--- -> 1 needs to perform several ms: $ {b - a} " def str1 for (int i in 1..10) { Str1 = '($ + $ eg44 EG3) * 2' DEF string2 = engine.createTemplate (str1) .make (Map) .toString () the println "$ {I} execution results: $ {-> shell.evaluate (string2 )} " } DEF C = System.currentTimeMillis () the println " take out 10 milliseconds: $ {C - B} " String str2 = '($ + $ EG10 EG1) *. 6' DEF string3 = engine.createTemplate (str2) .make (Map) .toString () the println "execution result: {$ -> shell.evaluate (string3)}" DEF D = System.currentTimeMillis () the println"----> 1 the number of execution times required in ms: $ D {-} C" DEF Str3 for ( int I in 1..100 ) { Str3 = '($ + $ eg44 EG3) * 2' DEF STRING4 = Engine .createTemplate (Str3) .make (Map) .toString () the println "$ {I} execution results: $ {-> shell.evaluate (STRING4)}" } DEF E = System.currentTimeMillis () the println "need to perform 100 times milliseconds: $ E {- D} " } }