Razorengine Performance Studies (reflection of the extended depth)

Source: Internet
Author: User

Let's start with a conclusion. 1) The razorengine is really slow, the compilation process is slow, and the compilation is still not suitable for a large number of repeated calls (one call can be accepted). 2) The relationship between Razorengine and ASP. Razor is unclear, so the conclusion here does not mean that ASP. NET MVC is slow. 3). NET 4.6 has a slightly higher reflection performance than. NET 2.0, and presumably the performance of the reflection assignment is raised from the native assignment of 1/5 to 1/4.
When testing razorengine here, an object property evaluator is implemented:
 
   
  
  1. using system diagnostics
  2. using razorengine
  3. using razorengine templating
  
 
  1. //脚本化的C#想写对还是有点麻烦的,还好Razor能给出有用的错误信息。
  2. public class RazorPropertySetter<TEntity> where TEntity :class
  3. {
  4. string PropertyName;
  5. bool Inited = false;
  6. private RazorPropertySetter(){ }
  7. public static RazorPropertySetter<TEntity> Create( string propertyName)
  8. {
  9. RazorPropertySetter<TEntity> rs = new RazorPropertySetter<TEntity>();
  10. rs.PropertyName = propertyName;
  11. return rs;
  12. }
  13. public void Set(TEntity entity , object value)
  14. {
  15. /span>string CacheKey = entity gettype (). fullname + "--" + this propertyname
  16. DynamicViewBag viewBag = new DynamicViewBag();
  17. viewBag.AddValue("PropertyValue", value);
  18. if (Inited == false)
  19. {
  20. string template = "@{model." + propertyname + "= Viewbag.propertyvalue;}"
  21. engine razor runcompile ( template CacheKey typeof tentity entity viewbag
  22. Inited = true;
  23. }
  24. else
  25. {
  26. Engine.Razor.Run(cacheKey, typeof(TEntity), entity, viewBag);
  27. }
  28. }
  29. }
  
 
  1. //测试用类
  2. public class TestData
  3. {
  4. public string Title { get; set; }
  5. }
  
 
  1. //测试代码
  2. TestData data = new TestData();
  3. data.Title = "V1";
  4. /span>razorpropertysetter < testdata > Settitle = razorpropertysetter < testdata >. create
  5. Stopwatch watch = new Stopwatch();
  6. watch.Start();
  7. setTitle.Set(data, "V00");
  8. watch.Stop();
Performance Test Results:

When there is time to study the performance of Script.net.

From for notes (Wiz)

Razorengine Performance Studies (reflection of the extended depth)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.