`

jesl的性能测试 其实发现都差不多

 
阅读更多
测试结果:
1000000次 ===>2833毫秒 100000次 ===>627毫秒



package com.eyu.ahxy.module.expression.jesl;

import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.MapContext;
import org.junit.Test;

/**
 * 1000000次 ===>2833毫秒 100000次 ===>627毫秒
 * @author bean
 */
public class JeslComplexTest {

	public static final int NUM = 1000000;

	public int getA() {
		return 10;
	}

	public int getB() {
		return 10;
	}

	JexlEngine jexl = new JexlEngine();
	String jexlExp = "Math.min(Math.floor(test.a*test.getB()),Math.floor(c+d*e))";
	// String jexlExp = "Math.min(3,5)";
	Expression e = jexl.createExpression(jexlExp);

	static JexlContext jc = new MapContext();
	static {
		jc.set("test", new JeslComplexTest());
		jc.set("Math", Math.class);
		jc.set("c", 10);
		jc.set("d", 10);
		jc.set("e", 2);

	}

	@Test
	public void compileTest() throws Exception {
		for (int i = 0; i < NUM; i++) {
			Object o = e.evaluate(jc);
			// System.err.println(o);
		}
	}

}





依赖的jar包:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl</artifactId>
<version>2.1.1</version>
</dependency>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics