Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:04:15+00:00 2026-06-03T17:04:15+00:00

I am trying to do some evaluation of template frameworks. For a simple performance

  • 0

I am trying to do some evaluation of template frameworks.

For a simple performance test I’m using these templates

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 <name>,"
                                       + "<group.users:{x| - <x.id> - <x.name>}> ";
// the group has 20 users
// 'Java' uses plain StringBuffer  

The part of Stringtemplate is

        ST st = new ST(stringTemplate);
        for (Map.Entry<String, Object> entry : vars.entrySet()) {
            st.add(entry.getKey(),entry.getValue());
        }

        start = System.currentTimeMillis();
        for (int n = 0; n < 10000; n ++) {
            st.render();
        }
        end = System.currentTimeMillis();

And the results are

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

Since I have no idea of string template, here is my question:

Is StringTemplate really that slow or is there an other (faster) way to render a template with it.

Update:

vars looks like this:

    Map<String,Object> vars = new HashMap<String,Object>();
    Group g = new Group("group1");
    for (int i = 0; i < 20; i++) {
        g.addUser(new User(i, "user" + i));
    }

    vars.put("group", g);
    vars.put("name", "john");

now with 1.000.000 iterations per template and looped the whole benchmark 10 times

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  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:04:17+00:00Added an answer on June 3, 2026 at 5:04 pm

    part of what you are observing is likely a compiler warm-up issue. When I run the test I enclose below 10000, it takes 350ms on my computer. when I increased to 100,000 it takes 1225ms, which is only 3.5x more time not 10x more time. when I run it 1,000,000 I get 8397ms which is only about 7x the cost and time when it should be 10x. Clearly the compiler is doing something interesting here with optimization. For a long-running program, I would expect ST to do better in your tests. The garbage collector could also be doing something here. Try your examples with bigger loop lengths.

    Anyway, speed was not my first priority with ST v4, but thank you for pointing this out. I will probably look into optimizing at some point. I don’t think I’ve even run a profiler on it.

        import org.stringtemplate.v4.*;
    import java.util.*;
    
    public class T {
        public static class User {
        public int id;
        public String name;
        public User(int id, String name) {
            this.id= id;
            this.name = name;
        }   
        }   
        private static String stringTemplate = "Hello, my name is <name>,"
        + "<users:{x| - <x.id> - <x.name>}> ";
        public static void main(String[] args) {
        ST st = new ST(stringTemplate);
        List<User> users = new ArrayList<User>();
            for (int i=1; i<=5; i++) {
            users.add(new User(i, "bob"+i));
            }   
        st.add("users", users);
        st.add("name", "tjp");
    
            long start = System.currentTimeMillis();
            for (int n = 0; n < 1000000; n ++) {
                st.render();
            }   
            long end = System.currentTimeMillis();
        System.out.printf("%d ms\n", end-start);
        }   
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write some simple predicate using boost::lambda and I am getting
i'm trying to do some post/lazy evaluation of arguments on my strings. Suppose i've
I'm using Eclipse with C++ plugins on my macbook, trying some practice projects to
I am evaluation dapper but i already running into some problems. I am trying
I'm trying to improve the performance of a javascript snippet evaluator . These script
I'm trying to send some information to a server with Android using Monodroid. The
so I'm trying to intercept a javascript form submission using jquery, and having some
I am trying to process salary details of employees depends upon some schedule using
I'm trying to classify some data using SVM classification, implemented in weka library. My
Recently I was trying some practice programs in python and I came across this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.