public List <BenchmarkResult> Run(Type containerType, List <BenchmarkResult> existingBenchmarkResults) { var container = (IContainerAdapter)Activator.CreateInstance(containerType); var benchmarks = BenchmarkFactory.CreateBenchmarks().ToArray(); var containerBenchmarkResults = new List <BenchmarkResult>(); Console.WriteLine( "{0} {1}{2} {3,10} {4,10}", container.Name, container.Version, new string(' ', Math.Max(0, benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - container.Name.Length - container.Version.Length)), "Single", "Multi"); try { container.Prepare(); // Run each benchmark before start measuring to ensure that all root services has been resolved. // Exclude the "Prepare" benchmarks as they dispose the container. foreach (var benchmark in benchmarks.Where(b => !b.Name.StartsWith("Prepare"))) { if (benchmark.IsSupportedBy(container)) { benchmark.Warmup(container); } } foreach (var benchmark in benchmarks) { var benchmarkResult = existingBenchmarkResults.SingleOrDefault(b => b.ContainerInfo.Name == container.Name && b.BenchmarkInfo.Name == benchmark.Name); if (benchmarkResult == null) { benchmarkResult = new BenchmarkRunner(container, benchmark).Run(); } containerBenchmarkResults.Add(benchmarkResult); Console.WriteLine( " {0}{1} {2,10} {3,10}", benchmarkResult.BenchmarkInfo, new string(' ', benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - benchmarkResult.BenchmarkInfo.Name.Length), benchmarkResult.SingleThreadedResult, benchmarkResult.MultiThreadedResult); } } finally { container.Dispose(); } return(containerBenchmarkResults); }
public List <BenchmarkResult> Run(Type containerType, List <BenchmarkResult> existingBenchmarkResults) { var container = (IContainerAdapter)Activator.CreateInstance(containerType); var benchmarks = BenchmarkFactory.CreateBenchmarks().ToArray(); var containerBenchmarkResults = new List <BenchmarkResult>(); Console.WriteLine( "{0} {1}{2} {3,10} {4,10}", container.Name, container.Version, new string(' ', Math.Max(0, benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - container.Name.Length - container.Version.Length)), "Single", "Multi"); try { container.Prepare(); foreach (var benchmark in benchmarks) { var benchmarkResult = existingBenchmarkResults.SingleOrDefault(b => b.ContainerInfo.Name == container.Name && b.BenchmarkInfo.Name == benchmark.Name); if (benchmarkResult == null) { benchmarkResult = new BenchmarkRunner(container, benchmark).Run(); } containerBenchmarkResults.Add(benchmarkResult); Console.WriteLine( " {0}{1} {2,10} {3,10}", benchmarkResult.BenchmarkInfo, new string(' ', benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - benchmarkResult.BenchmarkInfo.Name.Length), benchmarkResult.SingleThreadedResult, benchmarkResult.MultiThreadedResult); } } finally { container.Dispose(); } return(containerBenchmarkResults); }
public static void Main(string[] args) { var containers = ContainerAdapterFactory.CreateAdapters().ToArray(); var benchmarks = BenchmarkFactory.CreateBenchmarks().ToArray(); var benchmarkResults = new List <BenchmarkResult>(); var existingBenchmarkResults = new List <BenchmarkResult>(); if (args != null && args.Any(a => a.Equals("-update", StringComparison.OrdinalIgnoreCase))) { existingBenchmarkResults.AddRange(XmlOutputReader.GetExistingBenchmarkResults(benchmarks, containers)); } foreach (var container in containers) { AppDomain childDomain = null; try { AppDomainSetup domainSetup = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, ApplicationName = AppDomain.CurrentDomain.SetupInformation.ApplicationName, LoaderOptimization = LoaderOptimization.MultiDomainHost }; childDomain = AppDomain.CreateDomain("AppDomain for " + container.Name, null, domainSetup); ContainerAdapterRuntime runtime = (ContainerAdapterRuntime)childDomain.CreateInstanceAndUnwrap( typeof(ContainerAdapterRuntime).Assembly.FullName, typeof(ContainerAdapterRuntime).FullName); var containerBenchmarkResults = runtime.Run(container.GetType(), existingBenchmarkResults); benchmarkResults.AddRange(containerBenchmarkResults); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine( " Container '{0}' failed: {1}", container.Name, ex.Message); Console.ResetColor(); } finally { if (childDomain != null) { AppDomain.Unload(childDomain); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } Console.WriteLine(); } IOutput output = new MultiOutput( new XmlOutput(), new HtmlOutput(), new MarkdownOutput(), new CsvOutput(), new CsvRateOutput(), new ChartOutput(), new ZipOutput(), new JsonOutput(), new GithubPagesOutput()); output.Create(benchmarks, benchmarkResults); Console.WriteLine("Done"); }
public static void Main(string[] args) { var containers = ContainerAdapterFactory.CreateAdapters().ToArray(); var benchmarks = BenchmarkFactory.CreateBenchmarks().ToArray(); var benchmarkResults = new List <BenchmarkResult>(); var existingBenchmarkResults = new List <BenchmarkResult>(); if (args != null && args.Any(a => a.Equals("-update", StringComparison.OrdinalIgnoreCase))) { existingBenchmarkResults.AddRange(XmlOutputReader.GetExistingBenchmarkResults(benchmarks, containers)); } foreach (var container in containers) { var containerBenchmarkResults = new List <BenchmarkResult>(); Console.WriteLine("{0} {1}", container.Name, container.Version); try { container.Prepare(); foreach (var benchmark in benchmarks) { var benchmarkResult = existingBenchmarkResults.SingleOrDefault(b => b.Container == container && b.Benchmark == benchmark); if (benchmarkResult == null) { benchmark.Warmup(container); benchmarkResult = benchmark.Measure(container); benchmark.Verify(container); } containerBenchmarkResults.Add(benchmarkResult); Console.WriteLine( " {0}{1} {2,10}", benchmarkResult.Benchmark.Name, new string(' ', benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - benchmarkResult.Benchmark.Name.Length), benchmarkResult.Time); } container.Dispose(); // All benchmarks of container have completed, now 'commit' results benchmarkResults.AddRange(containerBenchmarkResults); } catch (Exception ex) { Console.WriteLine(" " + container.Name + " failed: " + ex.Message); } Console.WriteLine(); } IOutput output = new MultiOutput( new HtmlOutput(), new MarkdownOutput(), new XmlOutput(), new CsvOutput(), new CsvRateOutput(), new ChartOutput()); output.Create(benchmarks, benchmarkResults); Console.WriteLine("Done"); }
public static void Main(string[] args) { var containers = ContainerAdapterFactory.CreateAdapters().ToArray(); var benchmarks = BenchmarkFactory.CreateBenchmarks().ToArray(); var benchmarkResults = new List <BenchmarkResult>(); var existingBenchmarkResults = new List <BenchmarkResult>(); if (args != null && args.Any(a => a.Equals("-update", StringComparison.OrdinalIgnoreCase))) { existingBenchmarkResults.AddRange(XmlOutputReader.GetExistingBenchmarkResults(benchmarks, containers)); } foreach (var container in containers) { var containerBenchmarkResults = new List <BenchmarkResult>(); Console.WriteLine( "{0} {1}{2} {3,10} {4,10}", container.Name, container.Version, new string(' ', benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - container.Name.Length - container.Version.Length), "Single", "Multi"); container.Prepare(); foreach (var benchmark in benchmarks) { var benchmarkResult = existingBenchmarkResults.SingleOrDefault(b => b.Container == container && b.Benchmark == benchmark); if (benchmarkResult == null) { benchmarkResult = new BenchmarkRunner(container, benchmark).Run(); } containerBenchmarkResults.Add(benchmarkResult); Console.WriteLine( " {0}{1} {2,10} {3,10}", benchmarkResult.Benchmark.Name, new string(' ', benchmarks.Select(b => b.Name.Length).OrderByDescending(n => n).First() - benchmarkResult.Benchmark.Name.Length), benchmarkResult.SingleThreadedResult, benchmarkResult.MultiThreadedResult); } container.Dispose(); // All benchmarks of container have completed, now 'commit' results benchmarkResults.AddRange(containerBenchmarkResults); Console.WriteLine(); } IOutput output = new MultiOutput( new XmlOutput(), new HtmlOutput(), new MarkdownOutput(), new CsvOutput(), new CsvRateOutput(), new ChartOutput(), new ZipOutput()); output.Create(benchmarks, benchmarkResults); Console.WriteLine("Done"); }