title: Stringtemplate low performance in comparison to Velocity and Mvel
body: <p>I am trying to do some evaluation of template frameworks. </p>
  
  <p>For a simple performance test I'm using these templates</p>
  
  <pre><code>private static String mvelTemplate = "Hello, my name is @{name},"
                                       + " @foreach{user : group.users} - @{user.id} - @{user.name} "
                                       + " @end{}";
  private static String velocityTemplate = "Hello, my name is ${name},"
                                           + "#foreach($user in $group.users) - ${user.id} - ${user.name}  #end " ;
  
  private static String stringTemplate = "Hello, my name is &lt;name&gt;,"
                                         + "&lt;group.users:{x| - &lt;x.id&gt; - &lt;x.name&gt;}&gt; ";
  // the group has 20 users
  // 'Java' uses plain StringBuffer  
  </code></pre>
  
  <p>The part of Stringtemplate is</p>
  
  <pre><code>        ST st = new ST(stringTemplate);
          for (Map.Entry&lt;String, Object&gt; entry : vars.entrySet()) {
              st.add(entry.getKey(),entry.getValue());
          }
  
          start = System.currentTimeMillis();
          for (int n = 0; n &lt; 10000; n ++) {
              st.render();
          }
          end = System.currentTimeMillis();
  </code></pre>
  
  <p>And the results are </p>
  
  <pre><code>Mvel.Compiled elapsed:68ms. ~147K per second
  Velocity Cache elapsed:183ms. ~54K per second
  StringTemplate elapsed:234ms. ~42K per second
  Java elapsed:21ms. ~476K per second
  </code></pre>
  
  <p>Since I have no idea of string template, here is my question: </p>
  
  <p>Is StringTemplate really that slow or is there an other (faster) way to render a template with it.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>vars looks like this:</p>
  
  <pre><code>    Map&lt;String,Object&gt; vars = new HashMap&lt;String,Object&gt;();
      Group g = new Group("group1");
      for (int i = 0; i &lt; 20; i++) {
          g.addUser(new User(i, "user" + i));
      }
  
      vars.put("group", g);
      vars.put("name", "john");
  </code></pre>
  
  <p>now with 1.000.000 iterations per template and looped the whole benchmark 10 times</p>
  
  <pre><code>Mvel.Compiled elapsed:7056ms. ~141K per second
  Velocity Cache elapsed:18239ms. ~54K per second
  StringTemplate elapsed:22926ms. ~43K per second
  Java elapsed:2182ms. ~458K per second  
  </code></pre>