首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Beetl1.2M1将模板的文本先以Byte形式输出,性能又大幅提高(更新)

2012-06-30 
Beetl1.2M1将模板的文本先以Byte方式输出,性能又大幅提高(更新)beetl是一个语法类似javascript的模板语言,

Beetl1.2M1将模板的文本先以Byte方式输出,性能又大幅提高(更新)

beetl是一个语法类似javascript的模板语言,可以用于代码生成和Web开发,易用性和性能非常好,功能也很全,如下是在性能上最新优化成功

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(); //使用字节流输出

?

欢迎访问beetl和关注beetl,现在已经提供beetl1.2M1.jar以及相应源码的下载

热点排行