branaway / Japid

A Java-based statically-typed fast template engine that can be used in any Java code. It has special adapter for use with the Play! Framework.
113 stars 18 forks source link

Adding japid to benchmark #60

Closed PerfectCarl closed 11 years ago

PerfectCarl commented 11 years ago

I want to add japid to the template framework benchmark

So I need to code a simple class that would instanciate a japid template engine, give a collection of Item as an input parameter and execute the thing.

Here's an example of code for another template engine

        // Some template engine specific code
        Properties p = new Properties();
        p.put("log.enabled", false);
        p.put("feature.smart_escape.enabled", false);
        p.put("feature.transform.enabled", false);

        // here we go 
        engine = new RythmEngine(p);

        // Parameters
        String tmpl = "path/to/my/template.rythm.html" ; 
        List<Stock> items = ...
        OutputStream o1 = ... 

        // Get the template output in the output stream o1  
        engine.render(o1, tmpl, items);
        o1.close();

Could you help me writing the code for japid ?

PerfectCarl commented 11 years ago

See if that helps : https://github.com/branaway/Japid/blob/master/documentation/manual/Japid_Generic_Engine.textile

branaway commented 11 years ago

Assuming you have a folder named "plainjapid" in your application root and your template is:

"plainjapid/japidviews/my/view.html"

final String UNI = "universe";

JapidRenderer.init(OpMode.prod, "plainjapid", 1, null);

for (...) {

String r = JapidRenderer.renderWith("my.view", UNI);

System.out.println(r); }

I assumed you were testing against Japid and not Japid42, which is for integration with Play2.

2013/10/1 PerfectCarl notifications@github.com

See if that helps : https://github.com/branaway/Japid/blob/master/documentation/manual/Japid_Generic_Engine.textile

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-25393900 .

branaway commented 11 years ago

import cn.bran.japid.template;

import cn.bran.japid.compiler.OpMode;

2013/10/1 Bing Ran bing.ran@gmail.com

Assuming you have a folder named "plainjapid" in your application root and your template is:

"plainjapid/japidviews/my/view.html"

final String UNI = "universe";

JapidRenderer.init(OpMode.prod, "plainjapid", 1, null);

for (...) {

String r = JapidRenderer.renderWith("my.view", UNI);

System.out.println(r); }

I assumed you were testing against Japid and not Japid42, which is for integration with Play2.

2013/10/1 PerfectCarl notifications@github.com

See if that helps : https://github.com/branaway/Japid/blob/master/documentation/manual/Japid_Generic_Engine.textile

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-25393900 .

PerfectCarl commented 11 years ago

Thanks for your help, it is almost working. But I have an error :

     [java] java.lang.IllegalArgumentException: wrong number of arguments
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:597)
     [java]     at cn.bran.japid.util.RenderInvokerUtils.render(RenderInvokerUtils.java:26)
     [java]     at cn.bran.japid.template.JapidPlainController.invokeRender(JapidPlainController.java:76)
     [java]     at cn.bran.japid.template.JapidPlainController.getRenderResultWith(JapidPlainController.java:205)
     [java]     at cn.bran.japid.template.JapidPlainController.renderJapidWith(JapidPlainController.java:106)
     [java]     at cn.bran.japid.template.JapidRenderer.renderWith(JapidRenderer.java:729)
     [java]     at teb.Japid.renderToString(Japid.java:87)
     [java]     at teb.Japid.execute(Japid.java:64)
     [java]     at teb._BenchBase.run(_BenchBase.java:72)
     [java]     at teb.Japid.main(Japid.java:97)

Here's my code :

        final String UNI = "universe";
        JapidRenderer.init(OpMode.dev, "templates", 1, null);
        output = JapidRenderer.renderWith(template, UNI);

And here's my template :

`args String test 

TEST

By the way, it there any way to have a look at the generated classes ? Where are the generated source file generated ?

PerfectCarl commented 11 years ago

Okay, my bad. I was using the wrong template.

branaway commented 11 years ago

The generated Java classes are next to the Japid scripts.

Use prod mode when you do the benchmarking.

2013/10/1 PerfectCarl notifications@github.com

Okay, my bad. I was using the wrong template.

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-25456670 .

PerfectCarl commented 11 years ago

So I need to run the code once in dev mode to generate the file, and then in prod to do the benchmark. Is that right ?

branaway commented 11 years ago

It's not needed. It will get compiled when the Japid engine is initialized.

2013/10/1 PerfectCarl notifications@github.com

So I need to run the code once in dev mode to generate the file, and then in prod to do the benchmark. Is that right ?

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-25458110 .

PerfectCarl commented 11 years ago

When I use prod mode, I get this error :

     [java] java.lang.RuntimeException: java.lang.ClassNotFoundException: japidviews.japid
     [java]     at cn.bran.japid.template.JapidPlainController.getRenderResultWith(JapidPlainController.java:197)
     [java]     at cn.bran.japid.template.JapidPlainController.renderJapidWith(JapidPlainController.java:106)
     [java]     at cn.bran.japid.template.JapidRenderer.renderWith(JapidRenderer.java:729)
     [java]     at teb.Japid.renderToString(Japid.java:85)
     [java]     at teb.Japid.execute(Japid.java:64)
     [java]     at teb._BenchBase.run(_BenchBase.java:72)
     [java]     at teb.Japid.main(Japid.java:94)
     [java] Caused by: java.lang.ClassNotFoundException: japidviews.japid
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
     [java]     at java.security.AccessController.doPrivileged(Native Method)
     [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
     [java]     at cn.bran.japid.template.JapidPlainController.getRenderResultWith(JapidPlainController.java:194)
     [java]     ... 6 more

Should my template be stored in different folder for production mode ?

PerfectCarl commented 11 years ago

When I get the produced string I get the following lines at start :

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

Is this because I am in dev mode ?

branaway commented 11 years ago

To disable the verbose output in dev mode:

cn.bran.japid.util.JapidFlags.verbose = false;

2013/10/1 PerfectCarl notifications@github.com

When I get the produced string I get the following lines at start :

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

[JapidRender]: All java files are up to date.

Is this because I am in dev mode ?

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-25460731 .

PerfectCarl commented 11 years ago

Hey,

I'm done with porting japid to the benchmark.

I still have issue with the production mode hint that you gave me.

That being said, would you be kind enough to have a look at my use of japid. Here's the java file invoking the engine and here's the template

Do you see any thing that can hinder the performance of japid ? The rendering is executed many times : maybe there is a way to keep the compiled template in memory (if that's not the case already).

branaway commented 11 years ago

I'll take a look at the prod issue in a bit.

The "open for" loop in the template comes with performance cost if you try to avoid any overhead.

Using generic for loop will help.

@int _index = 1; @boolean _isOdd = true; @for (Stock item: items) { ... ... @ _index++; _isOdd = !_isOdd; @}

The render class should have been cached already. So nothing to tweak there.

But there would be no performance if it runs in dev mode. Stay tuned for my diagnose.

2013/10/18 PerfectCarl notifications@github.com

Hey,

I'm done with porting japid to the benchmark.

I still have issue with the production mode hint that you gave me.

That being said, would you be kind enough to have a look at my use of japid. Here's the (java file) [ https://github.com/PerfectCarl/template-engine-benchmarks/blob/master/src/teb/Japid.java] invoking the engine and here's (the template) [ https://github.com/PerfectCarl/template-engine-benchmarks/blob/master/templates/japidviews/japid.html ]

Do you see any thing that can hinders the performance of japid ? The rendering is executed many times : maybe there is a way to keep the compiled template in memory if that's not the case already.

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-26538464 .

branaway commented 11 years ago

Thanks for reporting I actually have found an obvious bug. Please try version 0.9.31 to get the fix.

PerfectCarl commented 11 years ago

Great. Oh and, not that I expect it would be a surprise for you, but japid's performance are easily among the best. Le 18 oct. 2013 10:59, "branaway" notifications@github.com a écrit :

Thanks for reporting I actually have found an obvious bug. Please try version 0.9.31 to get the fix.

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-26580970 .

branaway commented 11 years ago

cool to know that.

bing ran, en route

在 2013年10月18日,17:10,PerfectCarl notifications@github.com 写道:

Great. Oh and, not that I expect it would be a surprise for you, but japid's performance are easily among the best. Le 18 oct. 2013 10:59, "branaway" notifications@github.com a écrit :

Thanks for reporting I actually have found an obvious bug. Please try version 0.9.31 to get the fix.

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-26580970 .

— Reply to this email directly or view it on GitHub.

PerfectCarl commented 11 years ago

It works great. Though, I have the following error

[Japid] [error] could not find the apply() with japid class: null

Is this a warning ?

branaway commented 11 years ago

The message was misleading. Fixed it in version 0.9.32 plus an important bug fix in tracking the source code of Japid classes. Please upgrade.

2013/10/18 PerfectCarl notifications@github.com

It works great. Though, I have the following error

[Japid] [error] could not find the apply() with japid class: null

Is this a warning ?

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-26588824 .

PerfectCarl commented 11 years ago

Will do. Thanks for your work. Le 19 oct. 2013 14:56, "branaway" notifications@github.com a écrit :

The message was misleading. Fixed it in version 0.9.32 plus an important bug fix in tracking the source code of Japid classes. Please upgrade.

2013/10/18 PerfectCarl notifications@github.com

It works great. Though, I have the following error

[Japid] [error] could not find the apply() with japid class: null

Is this a warning ?

— Reply to this email directly or view it on GitHub< https://github.com/branaway/Japid/issues/60#issuecomment-26588824> .

— Reply to this email directly or view it on GitHubhttps://github.com/branaway/Japid/issues/60#issuecomment-26649190 .