Thursday, 15 January 2015

asp.net mvc - Is there a performance cost using razor views vs embeded code in class controller? -



asp.net mvc - Is there a performance cost using razor views vs embeded code in class controller? -

after request had been compiled , called few time, there performance difference between :

public actionresult index() { homecoming view("~/views/index.cshtml"); }

and

public actionresult index() { var sb = new stringbuilder(); sb.append("<html><body>bla bla bla bla</body></html>"); homecoming content(sb.tostring()); }

i sense @ utilize there one.

is compiled code resulting razor parsing aproximatively same of using stringbuilder or totally different ?

the reply depends on content contained in view. used glimpse measure time render index() method, 1 time using view() , returning content() sample html gave. in both cases, time equal - 300 - 400ms each. 1 time set html in view though, took bit longer finish request, 600 - 700ms.

overall i'd using content() might bit quicker, since there no razor parser involved when returning it.

asp.net-mvc

No comments:

Post a Comment