-
Notifications
You must be signed in to change notification settings - Fork 34
Performance
Ivaylo Kenov edited this page Aug 20, 2016
·
4 revisions
The expression parsing gives small overhead when generating links but the overall performance is quite good (you can see the PerformanceTest sample project)
// * All these measurements are collected using System.Diagnostics.Stopwatch. It is not the best way
// * to measure execution time but it gives enough information to compare how much slower is one method to another.
// * All measurements are for exactly 5000 generated URLs.
// Expressions without parameters
urlHelper.Action("Action", "My"); // ~8ms
urlHelper.Action<MyController>(c => c.Action()); // ~35ms
// Expressions with constant parameters
urlHelper.Action("Action", "My", new { id = 1, text = "text" }); // ~28 ms
urlHelper.Action<MyController>(c => c.Action(1, "text")); // ~39 ms
// Expression with variables as parameters
urlHelper.Action("Action", "My", new { id, text }); // ~22 ms
urlHelper.Action<MyController>(c => c.Action(id, text)); // ~51 ms
// Expression with model objects as values
urlHelper.Action("Action", "My", new { id, model = new Model { Integer = 2, String = "text" } }); // ~15 ms
urlHelper.Action<MyController>(c => c.Action(id, new Model { Integer = 2, String = "text" })); // ~48 ms