QLExpress脚本语言技术讲解(3) -----QL的性能描述

一.通过上篇QLExpress的例子我们知道了它的执行过程,总结为五个阶段

单词分析
单词类型分析
语法分析
生成指令
执行指令
其中前4个过程涉及语法的匹配运算等非常耗时,要做到使qlExpress的性能最大化,你可以做以下两方面的优化:

1、ExpressRunner设置成singleton(结合spring是非常容易做到的)
2、execute方法的参数设置  isCache =true(它会把 expressString 编译成一段指令,缓存在内存中,相当于缓存了(1)->(4)的过程)
二.测试qlexpress性能

public static void main(String[] args) throws Exception{
        Stopwatch s = Stopwatch.createStarted();
        ExpressRunner runner = new ExpressRunner(false,true);
        String express = "10 * 10 + 1 + 2 * 3 + 5 * 2";
        //isCache设置成false
        Object r = runner.execute(express,null, null, false,false);
        for(int i = 0;i<10000;i++){
            runner.execute(express,null, null, false,true);
            System.out.println("表达式计算:" + express + " = " + r);
        }
        System.out.println(s.stop());
    }
运行耗时:  9.123 s

通过设置isCache=true

 public static void main(String[] args) throws Exception{
        Stopwatch s = Stopwatch.createStarted();
        ExpressRunner runner = new ExpressRunner(false,true);
        String express = "10 * 10 + 1 + 2 * 3 + 5 * 2";
        Object r = runner.execute(express,null, null, true,false);
        for(int i = 0;i<10000;i++){
            runner.execute(express,null, null, true,true);
            System.out.println("表达式计算:" + express + " = " + r);
        }
        System.out.println(s.stop());
    }
运行耗时:2.976 s

同时可以观察控制台的打印信息,未设置isCache=true时候,控制台会反复进行1-5阶段

isCache只进行了一次1-5阶段的解析;

摘文

https://blog.csdn.net/express_wind
QlExpress-detail.jpg

 

https://github.com/alibaba/QLExpress

转载于:https://my.oschina.net/xiaominmin/blog/3096749

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值