还是以以前的模板为准(大小6K),循环渲染50000次,需要时间(毫秒为单位)如下
Beetl1.2M1 解释执行方式(普通模式),运行三次,分别 1356,1365,1348
Beetl1.2M1 编译执行方式(普通模式),运行三次,分别 913,922,905
Freemarker 分别是 1155,1130,1122
Beetl1.2M1 允许字节流优化,解释方式执行三次,分别是 587,605,610
Beetl1.2M1 允许字节流优化,编译方式执行三次,分别是 385,355,370
如下式一个采用节流优化,编译方式执行 的class代码
行17 输出V0,此处借鉴了Freemarker合并多行,一次性输出的功能,此优化对性能影响也很大
行18-32 是对includeFileTemplate 标签的处理,类似JSP的include
行39-42 是将模板中的文本预先转化成字节数组
行48 是行映射,也就是在渲染出错的时候,可以将java报错的行数与模板文件行数对应起来,以方便的查看错误原因,如19=3 表示java代码19行如果抛错,则对应的是模板中的第三行错误
package ext;
import java.util.*;
import java.util.Map.Entry;
import java.math.*;
import java.io.*;
import org.bee.tl.core.*;
import org.bee.tl.core.io.*;
import org.bee.tl.core.compile.*;
/* /ext/master_template.html is generated by beetl on 2012-06-22 10:42:38 */
public class master_template_html extends CompiledClass{
public void service(ByteWriter writer,Context ctx) throws IOException,BeeException{
ctx.set("__group",group);
ctx.set("__this",template);
CompileTemplateWriter out = new CompileTemplateWriter(writer,this);
ctx.set("__pw",out);
try{
out.write(__V0);
ByteSupportTag includeFileTemplate_18_19 = (ByteSupportTag)this.getTag("includeFileTemplate");
includeFileTemplate_18_19.setParas(new Object[]{"/ext/child_template.html"});
includeFileTemplate_18_19.setContext(ctx.getNewContext());
if(includeFileTemplate_18_19.requriedInput()){
out= out.getTempWriter();
ctx.set("__pw",out);
{
out.write(__V1);
}
//还原输出流
includeFileTemplate_18_19.setByteInput(out.getTempByte());
out = out.getParent();
ctx.set("__pw",out);
}
out.write(includeFileTemplate_18_19.getOutputAsByte());
out.write(__V2);
}catch(Exception ex){
throw getException(ex,lineMap);
}
out.flush();
}
private static final byte[] __V1 = new byte[]{0x68,0x65,0x6c,0x6c,0x6f,0x2c,0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x74,0x65,0x6d,0x70,0x20,0x63,0x68,0x69,0x6c,0x64,0xd,0xa};
private static final byte[] __V0 = new byte[]{0xffffffd5,0xffffffe2,0xffffffca,0xffffffc7,0x6d,0x61,0x73,0x74,0x65,0x72,0xffffffd2,0xffffffb3,0xffffffc3,0xffffffe6,0xd,0xa,0xffffffcf,0xffffffd6,0xffffffd4,0xffffffda,0xffffffcf,0xffffffd4,0xffffffca,0xffffffbe,0x63,0x68,0x69,0x6c,0x64,0xffffffd2,0xffffffb3,0xffffffc3,0xffffffe6,0xffffffd4,0xffffffda,0xffffffcf,0xffffffc2,0xffffffc3,0xffffffe6,0xd,0xa};
private static final byte[] __V2 = new byte[]{0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0x3d,0xd,0xa,0xffffffcf,0xffffffd6,0xffffffd4,0xffffffda,0xffffffca,0xffffffc7,0x6d,0x61,0x73,0x74,0x65,0x72,0xffffffd2,0xffffffb3,0xffffffc3,0xffffffe6};
private static final byte[] __VCR = new byte[]{0xd,0xa};
/* 原模板Cached标示*/
public long getVersion(){
return 1337956717968l;
}
/* 行映射*/
protected String lineMap = "-32=3-19=3-21=3-";
}
可见,字节流优化对性能影响很大,最快方式是beetl编译方式,且允许字节流优化。超过了Freemarker4倍。
对于使用者来说,只需俩行命令就可以了
group.enableOptimize(); //编译成class运行
group.enableDirectOutputByte(); //使用字节流输出
相关推荐
6. **性能优化**:了解如何配置和优化Restlet以提高服务性能,例如使用线程池、缓存策略等。 7. **测试**:使用Restlet提供的测试工具或者第三方工具对REST服务进行测试,确保其正常工作并满足性能要求。 总之,...
- BigBang:用户可以轻松地将文本中的单词或短语进行智能拆分,便于后续的选择、搜索、分享或复制操作。 - **语音识别**:与讯飞语音输入的合作,进一步提升了Smartisan OS 3.x在语音识别领域的表现,使得整个系统...
标签:archiva-configuration-1.2-M1.jar,archiva,configuration,1.2,M1,jar包下载,依赖包
标签:archiva-common-1.2-M1.jar,archiva,common,1.2,M1,jar包下载,依赖包
标签:archiva-security-1.2-M1.jar,archiva,security,1.2,M1,jar包下载,依赖包
标签:archiva-cli-1.2-M1.jar,archiva,cli,1.2,M1,jar包下载,依赖包
标签:archiva-policies-1.2-M1.jar,archiva,policies,1.2,M1,jar包下载,依赖包
标签:archiva-converter-1.2-M1.jar,archiva,converter,1.2,M1,jar包下载,依赖包
标签:archiva-scheduled-1.2-M1.jar,archiva,scheduled,1.2,M1,jar包下载,依赖包
标签:archiva-rss-1.2-M1.jar,archiva,rss,1.2,M1,jar包下载,依赖包
标签:archiva-rss-1.2-M1-javadoc.jar,archiva,rss,1.2,M1,javadoc,jar包下载,依赖包
标签:archiva-scheduled-1.2-M1-javadoc.jar,archiva,scheduled,1.2,M1,javadoc,jar包下载,依赖包
标签:archiva-cli-1.2-M1-javadoc.jar,archiva,cli,1.2,M1,javadoc,jar包下载,依赖包
标签:archiva-security-1.2-M1-javadoc.jar,archiva,security,1.2,M1,javadoc,jar包下载,依赖包
标签:archiva-rss-1.2-M1-sources.jar,archiva,rss,1.2,M1,sources,jar包下载,依赖包
标签:archiva-xmlrpc-services-1.2-M1.jar,archiva,xmlrpc,services,1.2,M1,jar包下载,依赖包
标签:archiva-cli-1.2-M1-sources.jar,archiva,cli,1.2,M1,sources,jar包下载,依赖包
标签:archiva-policies-1.2-M1-sources.jar,archiva,policies,1.2,M1,sources,jar包下载,依赖包
标签:archiva-consumer-api-1.2-M1.jar,archiva,consumer,api,1.2,M1,jar包下载,依赖包
标签:archiva-common-1.2-M1-sources.jar,archiva,common,1.2,M1,sources,jar包下载,依赖包