razor - Appaling RazorEngine 3.3 performance, compared to StringTemplate4 -


is there reason or doing wrong, why razorengine slow parse 100 different templates? looking stringtemplate, , performed 2 tests compare, per below.

    [test]     public void teststringtemplate()     {         csstopwatch stopwatch = new csstopwatch();         stopwatch.start();         stringbuilder sb = new stringbuilder();          (int = 0; < 100; i++)         {             string template = @"hello there name <name> <surname> "  + i;             textparsetests.testmodel model = new textparsetests.testmodel();             model.name = "karl";             model.surname = "cassar";              template t = new template(template);             t.add("name", model.name);             t.add("surname", model.surname);              var result = t.render();             sb.appendline(result);         }         stopwatch.stop();         var ms = stopwatch.elapsedmilliseconds;         int k = 5;         //109ms     }      [test]     public void testrazorengine()     {         csstopwatch stopwatch = new csstopwatch();         stopwatch.start();         stringbuilder sb = new stringbuilder();          (int = 0; < 100; i++)         {             string template = @"hello there name @model.name @model.surname " + i;             textparsetests.testmodel model = new textparsetests.testmodel();             model.name = "karl";             model.surname = "cassar";               var result = razor.parse(template, model);             sb.appendline(result);         }         stopwatch.stop();         var ms = stopwatch.elapsedmilliseconds;         int k = 5;         //24000~ ms     } 

the difference staggering.

  • stringtemplatev4: 109ms
  • razorengine 3.3: 24,131ms

that on 200x slower stringtemplate! have lot of content using razorengine format, , prefer syntax razorengine way on stringtemplate. however, extremely, extremely slow.

any ideas if may doing wrong? please note using different templates on purpose, if use caching razorengine way faster (down 300 - 400ms) website has lot of tiny text different, , 'real-life' test do.

razor.parse compile template every time.

you shouldn't this. application should compile template once, or whenever template changed if template being modified whilst application running.

razor.compile(template, name);

following application should use

razor.run(name, model);

compare times against razor.run not razor.parse


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -