예제 #1
0
        public void PerformanceComparison()
        {
            var iterations = 100;

            var graphite         = new ConcurrentBag <long>();
            var graphiteAsync    = new ConcurrentBag <long>();
            var webapi           = new ConcurrentBag <long>();
            var webapiAsync      = new ConcurrentBag <long>();
            var guid             = Guid.NewGuid();
            var url              = $"performancetests/{{0}}/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var urlAsync         = $"performancetests/{{0}}/async/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var graphiteUrl      = string.Format(url, "graphite");
            var graphiteAsyncUrl = string.Format(urlAsync, "graphite");
            var webapiUrl        = string.Format(url, "webapi");
            var webapiAsyncUrl   = string.Format(urlAsync, "webapi");
            var inputModel       = new PerfInputModel
            {
                Value1 = "value1",
                Value2 = "value2",
                Value3 = "value3"
            };

            10.TimesParallel(() =>
            {
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(graphiteUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(webapiUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(graphiteAsyncUrl, inputModel), guid);
                Should_match_result(WebClient.PostJson <PerfInputModel, PerfOutputModel>(webapiAsyncUrl, inputModel), guid);
            });

            iterations.TimesParallel(() =>
            {
                graphite.Add(graphiteUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, PerfOutputModel>(x, inputModel)));
                webapi.Add(webapiUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, Handler.OutputModel>(x, inputModel)));
                graphiteAsync.Add(graphiteUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, PerfOutputModel>(x, inputModel)));
                webapiAsync.Add(webapiUrl.ElapsedMilliseconds(x => WebClient.PostJson <PerfInputModel, Handler.OutputModel>(x, inputModel)));
            });

            Console.WriteLine($"Graphite :      {graphite.Average()}ms");
            Console.WriteLine($"Graphite Async: {graphiteAsync.Average()}ms");
            Console.WriteLine($"Web Api:        {webapi.Average()}ms");
            Console.WriteLine($"Web Api Async:  {webapiAsync.Average()}ms");
        }
예제 #2
0
        public void Performance([Values(Host.Owin, Host.IISExpress)] Host host)
        {
            var guid             = Guid.Parse("6e7335ea-5968-4cf5-84a2-0b8ef560a865");
            var url              = $"performancetests/{{0}}/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var urlAsync         = $"performancetests/{{0}}/async/url1/{guid}/5?query1=query1&query2={guid}&query3=5";
            var graphiteUrl      = string.Format(url, "graphite");
            var graphiteAsyncUrl = string.Format(urlAsync, "graphite");
            var webapiUrl        = string.Format(url, "webapi");
            var webapiAsyncUrl   = string.Format(urlAsync, "webapi");
            var inputModel       = new PerfInputModel
            {
                Value1 = "value1",
                Value2 = "value2",
                Value3 = "value3"
            };

            Should_match_result(Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(graphiteUrl, inputModel), guid);
            Should_match_result(Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(webapiUrl, inputModel), guid);
            Should_match_result(Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(graphiteAsyncUrl, inputModel), guid);
            Should_match_result(Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(webapiAsyncUrl, inputModel), guid);

            3.Times(() =>
            {
                Thread.Sleep(5000);
                var comparison = PerformanceComparison.InMilliseconds(100, 20, 40);

                var graphite      = comparison.AddCase("Graphite", () => Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(graphiteUrl, inputModel));
                var graphiteAsync = comparison.AddCase("Graphite Async", () => Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(graphiteAsyncUrl, inputModel));
                var webapi        = comparison.AddCase("Web Api", () => Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(webapiUrl, inputModel));
                var webapiAsync   = comparison.AddCase("Web Api Async", () => Http.ForHost(host).PostJson <PerfInputModel, PerfOutputModel>(webapiAsyncUrl, inputModel));

                comparison.Run();

                File.AppendAllText(@"c:\temp\graphite.txt", $"{graphite.Average},{graphiteAsync.Average},{webapi.Average},{webapiAsync.Average}\r\n");
            });
        }