Esempio n. 1
0
        private static BenchmarkRunInfo AllGetBenchmarks(IConfig config, DotvvmTestHost testHost)
        {
            var runInfo = BenchmarkConverter.TypeToBenchmarks(typeof(DotvvmGetBenchmarks <TAppLauncher>), config);
            var cases   = runInfo.BenchmarksCases
                          .SelectMany(b => CreateBenchmarks(b, testHost, testHost.Configuration)).ToArray();

            return(new BenchmarkRunInfo(cases, runInfo.Type, runInfo.Config));
        }
Esempio n. 2
0
        private static BenchmarkRunInfo AllPostBenchmarks(IConfig config, DotvvmTestHost testHost)
        {
            Directory.CreateDirectory("testViewModels");
            var runInfo = BenchmarkConverter.TypeToBenchmarks(typeof(DotvvmPostbackBenchmarks <TAppLauncher>), config);
            var cases   = runInfo.BenchmarksCases
                          .SelectMany(b => CreatePostbackBenchmarks(b, testHost, testHost.Configuration))
                          .ToArray();

            return(new BenchmarkRunInfo(cases, runInfo.Type, runInfo.Config));
        }
Esempio n. 3
0
        public static void BenchmarkApplication <TAppLauncher>(
            BrowserTimeOptions browserTimeOptions,
            string resultDirectory
            )
            where TAppLauncher : IApplicationLauncher, new()
        {
            resultDirectory             = Path.GetFullPath(resultDirectory);
            var(builder, configuration) = DotvvmTestHost.InitializeBuilder <TAppLauncher>(DotvvmSamplesBenchmarker <TAppLauncher> .GetRootPath());
            var host = builder
                       .UseUrls("http://*:5004")
                       .UseKestrel()
                       .Build();
            var hostCancel = new CancellationTokenSource();
            var hostTask   = host.RunAsync(hostCancel.Token);

            Debug.Assert(configuration.Value != null);
            var hostName = GetLocalHostname();

            Console.WriteLine($"// hostname = {hostName}");
            var urls = DotvvmSamplesBenchmarker <TAppLauncher> .GetTestRoutes(configuration.Value);

            var allResults = new List <(string, BrowserTimeResults)>();

            foreach (var url in urls)
            {
                var absUrl = $"http://{hostName}:5004/{url.TrimStart('/')}";
                Console.WriteLine($"// Benchmarking page load time - {url}");

                try
                {
                    // warm up the server
                    Enumerable.Range(0, 40)
                    .Select(_ => new HttpClient().GetStringAsync(absUrl))
                    .Apply(Task.WhenAll)
                    .Wait();
                    var results = ParseResults(resultDirectory, RunBenchmark(browserTimeOptions, resultDirectory, absUrl), removeDir: true);
                    allResults.Add((url, results));
                    Console.WriteLine($"// Done ({string.Join(", ", results.MeasuredValues.Select(k => k.Key + ": " + k.Value))})");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Benchmarking failed: {ex}");
                }
            }
        }
Esempio n. 4
0
        public static IEnumerable <BenchmarkCase> CreateBenchmarks(BenchmarkCase b, DotvvmTestHost host, DotvvmConfiguration config)
        {
            var urls      = GetTestRoutes(config);
            var definiton = new ParameterDefinition(nameof(DotvvmGetBenchmarks <TAppLauncher> .Url), false, new object[] { }, false, typeof(string), 0);

            foreach (var url in urls)
            {
                try
                {
                    new DotvvmGetBenchmarks <TAppLauncher>(host)
                    {
                        Url = url
                    }.Get();
                }
                catch { continue; }
                yield return(BenchmarkCase.Create(b.Descriptor, b.Job, new ParameterInstances(new[] { new ParameterInstance(definiton, url, SummaryStyle.Default) }), b.Config));
            }
        }
Esempio n. 5
0
        public static BenchmarkRunInfo AllMvcBenchmarks(IConfig config, DotvvmTestHost testHost)
        {
            IEnumerable <BenchmarkCase> createMvcBenchmarks(BenchmarkCase b)
            {
                var urls      = new[] { "/Home/Index" };
                var definiton = new ParameterDefinition(nameof(DotvvmGetBenchmarks <TAppLauncher> .Url), false, new object[] { }, false, typeof(string), 0);

                foreach (var url in urls)
                {
                    new DotvvmGetBenchmarks <TAppLauncher> {
                        Url = url
                    }.Get();
                    yield return(BenchmarkCase.Create(b.Descriptor, b.Job, new ParameterInstances(new[] { new ParameterInstance(definiton, url, SummaryStyle.Default) }), config.CreateImmutableConfig()));
                }
            }

            var runInfo = BenchmarkConverter.TypeToBenchmarks(typeof(DotvvmGetBenchmarks <TAppLauncher>), config);
            var cases   = runInfo.BenchmarksCases.SelectMany(createMvcBenchmarks).ToArray();

            return(new BenchmarkRunInfo(cases, runInfo.Type, runInfo.Config));
        }
Esempio n. 6
0
        public static IEnumerable <BenchmarkCase> CreatePostbackBenchmarks(BenchmarkCase b, DotvvmTestHost host, DotvvmConfiguration config)
        {
            var urls               = GetTestRoutes(config);
            var urlDefinition      = new ParameterDefinition(nameof(DotvvmPostbackBenchmarks <TAppLauncher> .Url), false, new object[] { }, false, typeof(string), 0);
            var vmDefiniton        = new ParameterDefinition(nameof(DotvvmPostbackBenchmarks <TAppLauncher> .SerializedViewModel), false, new object[] { }, false, typeof(string), 0);
            var viewModelDirectory = Environment.GetEnvironmentVariable("DotvvmTests_ViewModelDirectory") ??
                                     Path.GetFullPath("testViewModels");

            Environment.SetEnvironmentVariable("DotvvmTests_ViewModelDirectory", viewModelDirectory);
            Directory.CreateDirectory(viewModelDirectory);
            var result = new ConcurrentBag <BenchmarkCase>();

            Parallel.ForEach(urls, url =>
            {
                try
                {
                    var html = host.GetRequest(url).Result.Contents;
                    foreach (var(json, name) in FindPostbacks(html))
                    {
                        var fname = $"{ new string(url.Where(char.IsLetterOrDigit).ToArray()) }";
                        File.WriteAllText(Path.Combine(viewModelDirectory, $"{fname}.json"), json);
                        try
                        {
                            new DotvvmPostbackBenchmarks <TAppLauncher>(host)
                            {
                                Url = url, SerializedViewModel = fname
                            }.Postback();
                        }
                        catch { continue; }
                        result.Add(BenchmarkCase.Create(b.Descriptor, b.Job, new ParameterInstances(new[] {
                            new ParameterInstance(urlDefinition, url, SummaryStyle.Default),
                            new ParameterInstance(vmDefiniton, fname, SummaryStyle.Default)
                        }), b.Config));

                        // let's take only the first working post request on a page
                        break;
                    }
                }
Esempio n. 7
0
 public static DotvvmTestHost CreateSamplesTestHost()
 {
     return(DotvvmTestHost.Create <TAppLauncher>(GetRootPath()));
 }