博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Thymeleaf模板性能测试
阅读量:7173 次
发布时间:2019-06-29

本文共 3542 字,大约阅读时间需要 11 分钟。

hot3.png

1

2

3

对于这三种模板的介绍可以在oschina上查看,对于前两者比较熟悉,对Thymeleaf是新的认识,Thymeleaf有一个地方本人很喜欢,模板页面静态或者动态打开可以正常显示,方便前端测试和后端分离开发,下面是对三者的性能测试。

通过  ,找到了测试工具TEB,  

__________________________________________________________________________________________________________________________

发现Beetl和FreeMarker测试弄能代码都已经实现,于是对Thymeleaf进行了添加, 这里本人第一次用Thymeleaf所以不清楚对Thymeleaf配置是否对它性能产生了影响,下面直接代码:

package kiang.tei;import kiang.teb.TebEngine;import kiang.teb.TebModel;import org.thymeleaf.TemplateEngine;import org.thymeleaf.context.Context;import org.thymeleaf.templateresolver.FileTemplateResolver;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.Writer;import java.util.HashMap;import java.util.Map;import java.util.Properties;/** * @author eyeLee(yinjun622@163.com) *         Time 2014/11/1. */public class Thymeleaf implements TebEngine {    private TemplateEngine engine;    @Override    public TebEngine init(Properties properties) throws Exception {        FileTemplateResolver templateResolver =  new FileTemplateResolver();        templateResolver.setPrefix("./src/kiang/tpl/");        templateResolver.setSuffix(".tpl");        templateResolver.setCharacterEncoding("UTF-8");        templateResolver.setTemplateMode("XHTML");        engine = new TemplateEngine();        engine.setTemplateResolver(templateResolver);        engine.initialize();        return this;    }    @Override    public void test(Map arguments, Writer writer) throws Exception {        Context ctx = new Context();        ctx.setVariables(arguments);        engine.process("thymeleaf",  ctx, writer);    }    @Override    public void test(Map arguments, OutputStream output) throws Exception {    }    @Override    public void shut() throws Exception {    }    @Override    public boolean isBinarySupport() {        return false;    }    public static void main(String args[]) throws Exception {        String source="UTF-8", target = "UTF-8";        Writer writer = new OutputStreamWriter(System.out, target);        Map data = new HashMap();        data.put("target", target);        data.put("models", TebModel.dummyModels(20));        Properties properties = new Properties();        properties.setProperty("source", source);        properties.setProperty("target", target);        properties.setProperty("binary", String.valueOf(true));        TebEngine engine = new Thymeleaf().init(properties);        engine.test(data, writer);        writer.flush();        engine.shut();    }}

页面代码:

    Thymeleaf!!!!!    

Template Engine Benchmark - Thymeleaf!!!!!

序号 编码 名称 日期

在TEB配置文件中添加Thymeleaf项:

#Thymeleafthy.name=Thymeleaf 2.1.3thy.site=http://thymeleaf.comthy.test=kiang.tei.Thymeleaf

完整代码地址:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

测试结果:

TPS       : 引擎的吞吐量, 单位时间内引擎渲染次数, 单位: 次/秒Time      : 引擎全部渲染的执行时间, 单位: 毫秒OnceIo    : 引擎单次渲染的IO次数, 单位: 次MassIo    : 引擎全部渲染的IO次数, 单位: 次OnceOut   : 引擎单次渲染的输出字节(字符)数, 单位: 字节/字符MassOut   : 引擎全部渲染的输出字节(字符)数, 单位: 字节/字符PermMem   : 内存消耗, 内存取新生代之外的内存(新生代内存会被很快回收), 单位: 字节

通过测试结果发现,Thymeleaf与beetl不在一个数量级上,在并发和渲染时间上有巨大的差距

 

 

 

转载于:https://my.oschina.net/smile622/blog/339884

你可能感兴趣的文章
CRF 及CRF++ 安装与解释
查看>>
SQL Server 合并复制的Article可以指定单个对象的更新方向
查看>>
hreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别
查看>>
npm常用命令
查看>>
String,StringBuffer和StringBuilder三者的讲解
查看>>
Understanding Digital Raw Capture
查看>>
(轉貼) 康乃爾筆記法(Cornell Method) (雜項)
查看>>
(原創) unnamed object的多型只能使用reference (C/C++)
查看>>
10种有用的CSS技巧
查看>>
linux命令tree用法详解
查看>>
matlab练习程序(TV模型图像修复)
查看>>
用户接口(UI)设计的 20 条原则
查看>>
Windows Azure HandBook (3) 浅谈Azure安全性
查看>>
div+css布局入门
查看>>
Linux 下Apache和Resin的安装
查看>>
HDU 2710 Max Factorv (素数模板 & 多种解法)
查看>>
Linux 启动流程
查看>>
获得汉字字符串的首个拼音字母的缩写
查看>>
RegularExpressionValidator控件与常用验证正则表达式大全小结
查看>>
Zookeeper集群的安装和使用
查看>>