Thursday, January 27, 2011

FreeMarker vs. GSP for Dynamic Template Rendering, Revisited.

First of all, many thanks to valuable comments and inputs given in my previous blog post about this topic, grails forum and Based on your comments and inputs I find out that the benchmarking test can be divided to 3 parts: Template Creation only, Rendering only and Both (Template Creation and Rendering). So, I update the benchmark application to support these 3 types of test. You can see the screen of updated benchmark application below:

The Result
Template Creation Rendering Both
FreeMarker 17,981ms 29,909ms 45,868ms
GSP In iteration 773, OutOfMemoryError: PermGen space 23,569ms In iteration 669, OutOfMemoryError: PermGen space

The table above is the results of the test executed in 1000 times. It is clear that GSP is the winner for Rendering, but Template Creation and Both is not comparable as GSP facing OutOfMemoryError.

So, I re-run the tests  for 500 times, please see the results below:
Template Creation Rendering Both
FreeMarker 15,885ms 33,279ms 47,032ms
GSP 379,783ms 23,346ms 420,874ms

Edited on 28-Jan-2011:
  • Running Both (Template Creation and Rendering) 500 times in Tomcat 7.0.6, FreeMarker takes 23,291ms and GSP takes 321,801ms.
  • Running Rendering tests 5,000 times using grails prod run-war, FreeMarker takes 177,624ms and GSP takes 142,105ms.
Edited on 29-Jan-2011:
  • Running Both (Template Creation and Rendering) 5,000 times in Tomcat 7.0.6, FreeMarker takes 174,828ms on first time, and I re-run the same test without restart the Tomcat, it takes 161,724ms. (I did tried to run the test 10,000 times, facing java.lang.OutOfMemoryError: Java heap space in iteration 5,442.)
How I Run The Benchmark Tests
I run the benchmarking tests with the following steps:
  1. Start the application using grails prod run-war.
  2. After the application was started, open or refresh the URL http://localhost:8080/freemarker-vs-gsp/benchmark/index in browser.
  3. Click on "Template Creation" link and wait for test completion and shutdown the application. Do the same for remaining links, start from step 1.
The Environment
Operating System: Puppy Linux 4.3.1
JDK:  1.6.0_20
Grails: 1.3.6
Plugins: freemarker 0.3 and freemarker-tags 0.5.8
Processor: Intel Pentium M 1.5GHz
Memory: 1285MB

The Configuration
grails.plugins.freemarkertags = [
   autoImport: false,
   asSharedVariables: true

Edited on 29-Jan-2011: defineFunctions configuration no longer supported, so I remove it, with the updated source code below.

The Source Code
You can download the complete source code of the benchmark application and run it yourself. If you run the tests, please post the test results under comment section.

If your application required dynamic rendering only, go for GSP, otherwise FreeMarker is a better option.

Like this blog?

Thanks for visiting! If you like what you see, I'd really appreciate you linking to it or otherwise sharing it with people you think would find it useful.

No comments: