Some tests with Handlebars, RazorEngine and SharpTAL below :
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
//RAZOR
string razorTemplate = @"@model ConsoleApplication4.Test
<h1>@Model.Title</h1>
@if(Model.Condition1)
{
<span>condition1 is true</span>
}
<div>
@foreach(var movie in Model.Movies)
{<span>@movie</span>}
</div>";
//burning
Engine.Razor.RunCompile(razorTemplate, "templateKey", typeof(Test), new Test());
sw.Start();
var result1 = Engine.Razor.RunCompile(razorTemplate, "templateKey", typeof(Test), new Test());
sw.Stop();
Console.WriteLine("razor : "+sw.Elapsed);
//SHARPTAL
string sharpTalTemplate = @"<h1>${Title}</h1>
<span tal:condition=""Condition1"">condition1 is true</span>
<div tal:repeat='movie Movies'>${movie}</div>";
var test = new Test();
var globals = new Dictionary<string, object>
{
{ "Movies", new List<string> {test.Movies[0],test.Movies[1],test.Movies[2] } },
{ "Condition1", test.Condition1 },
{ "Title", test.Title },
};
var tt = new Template(sharpTalTemplate);
tt.Render(globals);
sw.Restart();
var tt2 = new Template(sharpTalTemplate);
var result2 = tt2.Render(globals);
sw.Stop();
Console.WriteLine("sharptal : " + sw.Elapsed);
//HANDLEBARS
string handleBarsTemplate = @"<h1>{{Title}}</h1>
{{#if Condition1}}
<span>condition1 is true</span>
{{/if}}
<div>
{{#each Movies}}
<span>{{this}}</span>
{{/each}}
</div>";
var tt3 = Handlebars.Compile(handleBarsTemplate);
sw.Restart();
var result3 = tt3(new Test());
sw.Stop();
Console.WriteLine("handlebars : " + sw.Elapsed);
Console.WriteLine("-----------------------------");
Console.WriteLine(result1);
Console.WriteLine(result2);
Console.WriteLine(result3);
Console.ReadLine();
}
}
public class Test
{
public bool Condition1 { get; set; }
public List<string> Movies { get; set; }
public string Title { get; set; }
public Test()
{
Condition1 = true;
Movies = new List<string>() { "Rocky", "The Fifth Element", "Intouchables" };
Title = "Hi stackoverflow! Below you can find good movie list! Have a good day.";
}
}
}
and results :