public static void Main(string[] args) { var config = new ManualConfig(); config.Add(DefaultConfig.Instance); config.Add(Job.Default .WithLaunchCount(1) .WithIterationTime(TimeInterval.FromMilliseconds(500)) .WithWarmupCount(3) .WithTargetCount(6) ); BenchmarkRunner.Run <StringIteration>(config); }
static void Main(string[] args) { List <Type> benchmarks = GetBenchmarkTypesFromArgs(args); // Set the argument as the crash dump. We can't just set CrashDump here because it needs to be read from child processes. if (args.Length > 0) { Environment.SetEnvironmentVariable(DumpFileEnv, args[0]); } // We want to run this even if we don't use the result to make sure we can successfully load 'CrashDump'. int targetPointerSize = GetTargetPointerSize(); ManualConfig benchmarkConfiguration = ManualConfig.Create(DefaultConfig.Instance); // Windows supports x86 and x64 so we need to choose the correct version of .Net. Job job; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string dotnetPath = GetDotnetPath(targetPointerSize); if (targetPointerSize == 4) { job = Job.RyuJitX86.With(CsProjCoreToolchain.From(NetCoreAppSettings.NetCoreApp31.WithCustomDotNetCliPath(dotnetPath))); } else { job = Job.RyuJitX64.With(CsProjCoreToolchain.From(NetCoreAppSettings.NetCoreApp31.WithCustomDotNetCliPath(dotnetPath))); } } else { job = Job.Default; } string id = $"{RuntimeInformation.OSDescription} {RuntimeInformation.FrameworkDescription} {(targetPointerSize == 4 ? "32bit" : "64bit")}"; job = job.WithId(id) .WithWarmupCount(1) .WithIterationTime(TimeInterval.FromSeconds(1)) .WithMinIterationCount(5) .WithMaxIterationCount(10) .DontEnforcePowerPlan(); // make sure BDN does not try to enforce High Performance power plan on Windows benchmarkConfiguration.Add(job); if (benchmarks.Count == 0) { BenchmarkRunner.Run(Assembly.GetCallingAssembly(), benchmarkConfiguration); } else { foreach (Type t in benchmarks) { BenchmarkRunner.Run(t, benchmarkConfiguration); } } }
public void TestFilteringLoggerImportantArea() { var lines = LogInput.Split(new[] { "\r\n" }, StringSplitOptions.None); var output = new AccumulationLogger(); var logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); var config = new ManualConfig(); config.Add(logger); using (LoggerHelpers.BeginImportantLogScope(config)) { foreach (var line in lines) { logger.WriteLine(line); } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); var i = 0; foreach (var line in lines) { if (i++ % 2 == 0) { logger.WriteLineError(line); } else { logger.WriteLineHint(line); } } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); LogMessages(logger); // ReSharper disable once StringLiteralTypo const string Expected = @"ABCDEFGH TST0 // !TST1 TST2 // !<-- TST3 // !<-- TST4 TST5 // !--> TST6 // !--> TST7 TST8 // !TST9 TST10 "; Assert.AreEqual(output.GetLog(), Expected); } }
public static void Main(string[] args) { var config = new ManualConfig(); config.Add(DefaultConfig.Instance); config.Set(config.GetSummaryStyle().WithTimeUnit(TimeUnit.Nanosecond)); BenchmarkRunner.Run <Benchmarks>(config); }
static void Main(string[] args) { if (args.Length > 0 && args[0] == "make") { // make test data var sb = new StringBuilder(); for (var i = 1; i < 10000; i++) { sb.AppendLine(string.Join(null, Enumerable.Range(0, i))); } File.WriteAllText("testfile.txt", sb.ToString()); return; } var config = new ManualConfig(); config.Add(Job.ShortRun); config.Add(MarkdownExporter.GitHub); config.Add(MemoryDiagnoser.Default); config.Add(ConsoleLogger.Default); config.Add(DefaultColumnProviders.Instance); config.Add(ThreadingDiagnoser.Default); BenchmarkRunner.Run <Test>(config); }
static void RunTest <T>() where T : TestCollectionBase, new() { #if HIGH_PRECISION ManualConfig config = new ManualConfig(); config.Add(new Job("DefaultJob", RunMode.Default, EnvMode.RyuJitX64) { Env = { Runtime = Runtime.Clr }, Accuracy = { MaxStdErrRelative = 0.05, RemoveOutliers = true }, }); config.Add(ConsoleLogger.Default); config.Add(CsvExporter.Default, HtmlExporter.Default); var summary = BenchmarkRunner.Run <T>(config); #else for (int threads = 1; threads <= 2; threads++) { T test = new T() { Threads = threads }; test.Setup(); test.RunTests(); GC.Collect(); Stopwatch stopwatch = Stopwatch.StartNew(); const int n = 10; for (int i = 0; i < n; i++) { test.RunTests(); } GC.Collect(); stopwatch.Stop(); test.Dispose(); long operations = n * TestCollectionBase.Iterations; double ns = ((double)stopwatch.ElapsedTicks / operations) / (1E-9 * Stopwatch.Frequency); Console.WriteLine($"{typeof( T ).Name} with {threads} threads on each end: {ns:0.0} ns/op, {threads * 1E3 / ns:0.0} MT/s"); } #endif }
private static void Main() { ManualConfig configuration = DictionaryVsHashTableVsListTestHarness.Configuration; configuration.Add(new Job { Environment = { Runtime = Runtime.Clr } }); BenchmarkRunner.Run <DictionaryVsHashTableVsListTestHarness.Add>(configuration); BenchmarkRunner.Run <DictionaryVsHashTableVsListTestHarness.Change>(configuration); BenchmarkRunner.Run <DictionaryVsHashTableVsListTestHarness.Enumerate>(configuration); BenchmarkRunner.Run <DictionaryVsHashTableVsListTestHarness.Index>(configuration); BenchmarkRunner.Run <DictionaryVsHashTableVsListTestHarness.Remove>(configuration); }
static void Main(string[] args) { var config = new ManualConfig(); config.Add(Job.ShortRun); config.Add(MarkdownExporter.GitHub); config.Add(MemoryDiagnoser.Default); config.Add(ConsoleLogger.Default); config.Add(DefaultColumnProviders.Instance); config.Add(ThreadingDiagnoser.Default); BenchmarkRunner.Run <Program>(config); }
public static void Main(string[] args) { /** Uncomment to test using performance profiler */ if (args?.FirstOrDefault() == "profile") { //var benchmark = new LoadSimpleBenchmark(); var benchmark = new LoadComplexBenchmark(); //var benchmark = new SaveSimpleBenchmark(); //var benchmark = new SaveComplexBenchmark(); for (int i = 0; i < 1000; i++) { benchmark.PortableXaml(); //benchmark.PortableXamlNoCache(); //benchmark.SystemXaml(); //benchmark.SystemXamlNoCache(); } return; } /**/ // BenchmarkSwitcher doesn't automatically exclude abstract benchmark classes var types = typeof(MainClass) .Assembly .GetExportedTypes() .Where(r => typeof(IXamlBenchmark).IsAssignableFrom(r) && !r.IsAbstract); var config = new ManualConfig(); config.Add(DefaultConfig.Instance.GetLoggers().ToArray()); config.Add(DefaultConfig.Instance.GetExporters().ToArray()); config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); config.Add(JitOptimizationsValidator.DontFailOnError); config.Add(Job.Default); config.Add(MemoryDiagnoser.Default); config.Add(StatisticColumn.OperationsPerSecond); config.Add(RankColumn.Arabic); var switcher = new BenchmarkSwitcher(types.ToArray()); switcher.Run(args, config); }
static void Main(string[] args) { var configuration = new ManualConfig(); configuration.KeepBenchmarkFiles = false; configuration.Add(StatisticColumn.Min); configuration.Add(StatisticColumn.Max); configuration.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); configuration.Add(DefaultConfig.Instance.GetLoggers().ToArray()); configuration.Add(DefaultConfig.Instance.GetDiagnosers().ToArray()); configuration.Add(DefaultConfig.Instance.GetAnalysers().ToArray()); configuration.Add(DefaultConfig.Instance.GetJobs().ToArray()); configuration.Add(DefaultConfig.Instance.GetValidators().ToArray()); BenchmarkRunner.Run <SimpleCsvTester>(configuration); //var tester = new AsyncVsSyncTest(); //for (int i = 0; i != 10; ++i) //{ // tester.SyncTest(); //} //var stopwatch = Stopwatch.StartNew(); //string syncResult = tester.SyncTest(); //stopwatch.Stop(); //Console.Out.WriteLine($"Sync Execution Time: {stopwatch.Elapsed}"); //Console.Out.WriteLine($"Sync Result Count: {syncResult.Length}"); //for (int i = 0; i != 10; ++i) //{ // tester.AsyncTest().Wait(); //} //stopwatch.Restart(); //string asyncResult = tester.AsyncTest().Result; //stopwatch.Stop(); //Console.Out.WriteLine($"Async Execution Time: {stopwatch.Elapsed}"); //Console.Out.WriteLine($"Async Result Count: {asyncResult.Length}"); Console.Out.Write("Hit <enter> to exit..."); Console.In.ReadLine(); }
public static void Main() { var config = new ManualConfig(); config.Add(Job.Core); config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); config.Add(DefaultConfig.Instance.GetExporters().ToArray()); config.Add(DefaultConfig.Instance.GetDiagnosers().ToArray()); config.Add(DefaultConfig.Instance.GetAnalysers().ToArray()); config.Add(DefaultConfig.Instance.GetJobs().ToArray()); config.Add(DefaultConfig.Instance.GetValidators().ToArray()); config.Add(new MemoryDiagnoser()); config.UnionRule = ConfigUnionRule.AlwaysUseGlobal; var summary = BenchmarkRunner.Run <Program>(); var logger = ConsoleLogger.Default; MarkdownExporter.Console.ExportToLog(summary, logger); ConclusionHelper.Print(logger, config.GetCompositeAnalyser().Analyse(summary).ToList()); }
private static void runBenchmarks() { var configuration = new ManualConfig() { Options = ConfigOptions.KeepBenchmarkFiles }; configuration.Add(StatisticColumn.Min); configuration.Add(StatisticColumn.Max); configuration.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); configuration.Add(DefaultConfig.Instance.GetLoggers().ToArray()); configuration.Add(DefaultConfig.Instance.GetDiagnosers().ToArray()); configuration.Add(DefaultConfig.Instance.GetAnalysers().ToArray()); configuration.Add(DefaultConfig.Instance.GetJobs().ToArray()); configuration.Add(DefaultConfig.Instance.GetValidators().ToArray()); BenchmarkRunner.Run <CoreBenchmarkSuite>(configuration); Console.Out.Write("Hit <enter> to exit..."); Console.In.ReadLine(); }
public static void Main(string[] args) { new Tests.JsonAst.JsonAstLarge().VerifyAll(); new Tests.Json.JsonLarge().VerifyAll(); var config = new ManualConfig(); config.Add(DefaultConfig.Instance.GetLoggers().ToArray()); config.Add(DefaultConfig.Instance.GetExporters().ToArray()); config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); config.Add(JitOptimizationsValidator.DontFailOnError); config.Add(Job.Default); config.Add(MemoryDiagnoser.Default); config.Add(StatisticColumn.OperationsPerSecond); config.Add(RankColumn.Arabic); var switcher = BenchmarkSwitcher.FromAssembly(typeof(MainClass).Assembly); switcher.Run(args, config); }
/// <summary> /// Removes the default console logger, removes all exporters but default markdown exporter. /// </summary> // TODO: do not filter the exporters? public static ManualConfig CreateUnitTestConfig(IConfig template) { var result = new ManualConfig(); result.Add(template.GetColumns().ToArray()); //result.Add(template.GetExporters().ToArray()); result.Add(template.GetExporters().Where(l => l == MarkdownExporter.Default).ToArray()); result.Add(template.GetLoggers().Where(l => l != ConsoleLogger.Default).ToArray()); result.Add(template.GetDiagnosers().ToArray()); result.Add(template.GetAnalysers().ToArray()); result.Add(template.GetJobs().ToArray()); return(result); }
private IConfig CreateInProcessAndRoslynConfig(OutputLogger logger) { var config = new ManualConfig(); config.Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); config.Add(DefaultConfig.Instance.GetAnalysers().ToArray()); config.Add(DefaultConfig.Instance.GetExporters().ToArray()); config.Add(DefaultConfig.Instance.GetFilters().ToArray()); config.Add(DefaultConfig.Instance.GetLoggers().ToArray()); config.Add( Job.Dry .With(InProcessEmitToolchain.DontLogOutput) .WithInvocationCount(4) .WithUnrollFactor(4)); config.Add( Job.Dry .With(new RoslynToolchain()) .WithInvocationCount(4) .WithUnrollFactor(4)); config.Options |= ConfigOptions.KeepBenchmarkFiles; config.Add(logger ?? (Output != null ? new OutputLogger(Output) : ConsoleLogger.Default)); return(config); }
private IConfig CreateBenchmarkConfig(ICompetitionConfig competitionConfig) { // ReSharper disable once UseObjectOrCollectionInitializer var result = new ManualConfig(); // TODO: to overridable methods? result.KeepBenchmarkFiles = competitionConfig.KeepBenchmarkFiles; result.UnionRule = competitionConfig.UnionRule; result.Set(competitionConfig.GetOrderProvider()); result.Add(OverrideJobs(competitionConfig).ToArray()); result.Add(OverrideExporters(competitionConfig).ToArray()); result.Add(OverrideDiagnosers(competitionConfig).ToArray()); result.Add(GetLoggers(competitionConfig).ToArray()); result.Add(GetColumns(competitionConfig).ToArray()); result.Add(GetValidators(competitionConfig).ToArray()); result.Add(GetAnalysers(competitionConfig).ToArray()); return(result.AsReadOnly()); }
static void Main(string[] args) { var bench = new SampleBenchmark(); bench.Setup(); Console.WriteLine($"json: {bench.Utf8JsonWithType().Length:000,000,000} bytes"); Console.WriteLine($"json + gzip: {bench.Utf8JsonWithTypeGz().Length:000,000,000} bytes"); Console.WriteLine($"msgpack: {bench.MessagePackWithType().Length:000,000,000} bytes"); Console.WriteLine($"msgpack + lz4: {bench.MessagePackWithTypeLz4().Length:000,000,000} bytes"); Console.WriteLine($"msgpack (typeless): {bench.MessagePackTypeless().Length:000,000,000} bytes"); Console.WriteLine($"msgpack (typeless) + lz4: {bench.MessagePackTypelessLz4().Length:000,000,000} bytes"); var config = new ManualConfig(); config.Add(Job.ShortRun); config.Add(MarkdownExporter.GitHub); config.Add(MemoryDiagnoser.Default); config.Add(ConsoleLogger.Default); config.Add(DefaultColumnProviders.Instance); config.Add(ThreadingDiagnoser.Default); BenchmarkRunner.Run <SampleBenchmark>(config); }