简体   繁体   English

有谁知道Razor,Spark和NVelocity视图引擎之间的性能差异?

[英]Does anyone know the performance difference between Razor, Spark, and NVelocity view engines?

Has anyone done any have any performance numbers that compare the various viewengine implementations for ASP.NET MVC3? 有没有人有任何性能数字可以比较ASP.NET MVC3的各种viewengine实现? Specifically I'm interested in the differences in performance between Razor, Spark, and NVelocity. 具体来说,我对Razor,Spark和NVelocity之间的性能差异感兴趣。 I realize the last is a bit dated, but we use it for generating emails, and would like to replace it with RazorEngine. 我意识到最后一点有点过时,但我们用它来生成电子邮件,并想用RazorEngine替换它。

NVelocity used to be fast in its day, but I'm suspicious of its performance now as compared to the other, more modern viewengines. NVelocity曾经在当时很快,但我现在对其性能的怀疑与其他更现代的视觉引擎相比。

Any insight would be appreciated. 任何见解将不胜感激。

One of the authors of RazorEngine here. RazorEngine的作者之一。 The first compilation of a view is always slow. 视图的第一次编译总是很慢。 After that it's cached and should be fairly fast. 之后它被缓存并且应该相当快。 There's a new version coming out eventually that will be a basic rewrite. 最终会出现一个新版本,这将是一个基本的重写。 In addition I've already written a much smaller/simpler/hopefully faster version with the help of Sam Saffron. 另外,在Sam Saffron的帮助下,我已经写了一个更小/更简单/希望更快的版本。 (from this site) That said, I haven't done any performance tests of RazorEngine vs any other engine. (来自这个网站)那就是说,我没有对RazorEngine与任何其他引擎进行任何性能测试。

Razor itself is compiled (after the first call). Razor本身被编译(在第一次调用之后)。 If Spark and others are also compiled they might be just as fast. 如果Spark和其他人也被编译,他们可能同样快。 But at first glance I would assume * Razor to be faster after the first call due to native code vs. parsing the file on each call. 但是乍一看我会假设 * Razor在第一次调用后由于本机代码而不是在每次调用时解析文件而更快。

The simplest way to test would be to profile each one and make that determination for yourself. 最简单的测试方法是对每一个进行分析并为自己做出决定。 Everybody's environment will be different which could yield different results. 每个人的环境都会不同,可能产生不同的结果。

* We all know what assuming does * 我们都知道假设是什么

I know it's an old question, but after looking for better alternatives to razor I still think none of them is faster than nvelocity. 我知道这是一个老问题,但在寻找更好的剃须刀替代品后,我仍然认为它们都不比nvelocity快。 Razor gives you intellisense and is easier to code. Razor为您提供智能感知,并且更容易编码。 But nvelocity is MUCH faster. 但是nvelocity要快得多。 In the example below you'll find that razor takes 2 seconds to parse one line of text. 在下面的示例中,您会发现剃刀需要2秒才能解析一行文本。 NVelocity parses instantly. NVelocity立即解析。 I've tested this with template files as well, same result. 我也用模板文件对此进行了测试,结果相同。 2 seconds to parse is too slow for a commercial web application. 对于商业Web应用程序,解析2秒太慢。 So despite the fact that I like razor a lot more, I have no choice than to stick with NVelocity. 因此,尽管我更喜欢剃刀,但我别无选择,只能坚持使用NVelocity。

I'm not very sure about caching. 我不太确定缓存。 But in the case of string parsing (as opposed to file based parsing) as in the example below, there is no caching for razor. 但是在字符串解析的情况下(与基于文件的解析相反),如下例所示,razor没有缓存。

Simple asp.net example: 简单的asp.net示例:

protected void Page_Load(object sender, EventArgs e)
{
    string toParseText = "bladiebla $Model.SomeProperty";
    dynamic model = new ExpandoObject();
    model.SomeProperty = "hello";
    string result = Razor.Parse(toParseText, model);


    var _templateEngine = new VelocityEngine();
    _templateEngine.Init();
    var context = new VelocityContext();
    context.Put("Model", model);
    using (StringWriter writer = new StringWriter())
    {
        _templateEngine.Evaluate(context, writer, "", toParseText);
        string result2 = writer.ToString();
    }
}

NuGet: 的NuGet:

  • install-package RazorEngine 安装包RazorEngine
  • install-package nvelocity install-package nvelocity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM