Esempio n. 1
0
        // as described in http://www.codeproject.com/Articles/61964/Performance-Tests-Precise-Run-Time-Measurements-wi
        public static void Main()
        {
            PrepareTypedRouting();
            PrepareThread();

            var urlHelper = CreateUrlHelper();

            var id    = 1;
            var text  = "text";
            var model = new RequestModel {
                Integer = 2, String = "text"
            };

            // Actions without parameters - 7 ms VS 20 ms
            Console.WriteLine("Actions without parameters");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\")",
                          () => urlHelper.Action("Action", "My")); // ~7 ms

            RunAndMeasure("(c => c.Action())",
                          () => urlHelper.Action <MyController>(c => c.Action())); // ~20 ms

            Console.WriteLine(new string('-', 40));

            // Actions with constant parameters - 8 ms VS 25 ms
            Console.WriteLine("Actions with constant parameters");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\", new { id = 1, text = \"text\" })",
                          () => urlHelper.Action("Action", "My", new { id = 1, text = "text" })); // ~8 ms

            RunAndMeasure("(c => c.Action(1, \"text\"))",
                          () => urlHelper.Action <MyController>(c => c.Action(1, "text"))); // ~25 ms

            Console.WriteLine(new string('-', 40));

            // Actions with variable primitive parameters - 8 ms VS 499 ms
            Console.WriteLine("Actions with variable primitive parameters");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\", new { id, text })",
                          () => urlHelper.Action("Action", "My", new { id, text })); // ~8 ms

            RunAndMeasure("(c => c.Action(id, text))",
                          () => urlHelper.Action <MyController>(c => c.Action(id, text))); // ~499 ms

            Console.WriteLine(new string('-', 40));

            // Actions with variable primitive parameters (using With.No<T>) - 7 ms VS 70 ms
            Console.WriteLine("Actions with variable primitive parameters (using With.No<T>)");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\", new { id, text })",
                          () => urlHelper.Action("Action", "My", new { id, text })); // ~7 ms

            RunAndMeasure("(c => c.Action(id, text))",
                          () => urlHelper.Action <MyController>(c => c.Action(With.No <int>(), With.No <string>()), new { id, text })); // ~70 ms

            Console.WriteLine(new string('-', 40));

            // Actions with variable reference parameters - 7 ms VS 692 ms
            Console.WriteLine("Actions with variable reference parameters");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\", new { id, model })",
                          () => urlHelper.Action("Action", "My", new { id, model })); // ~7 ms

            RunAndMeasure("(c => c.Action(id, model))",
                          () => urlHelper.Action <MyController>(c => c.Action(id, model))); // ~692 ms

            Console.WriteLine(new string('-', 40));

            // Actions with variable reference parameters (using With.No<T>) - 8 ms VS 67 ms
            Console.WriteLine("Actions with variable reference parameters (using With.No<T>)");
            Console.WriteLine(new string('-', 40));

            RunAndMeasure("(\"action\", \"controller\", new { id, model })",
                          () => urlHelper.Action("Action", "My", new { id, model })); // ~8 ms

            RunAndMeasure("(c => c.Action(With.No<int>(), With.No<RequestModel>()))",
                          () => urlHelper.Action <MyController>(c => c.Action(With.No <int>(), With.No <RequestModel>()), new { id, model })); // ~67 ms

            Console.WriteLine(new string('-', 40));
        }
Esempio n. 2
0
 public IActionResult Action(int id, RequestModel model)
 {
     return(null);
 }