private static void RunAndPrint <T>(string name)
        {
            var r       = BenchmarkConverter.TypeToBenchmarks(typeof(T), new C(name));
            var ass     = AppDomain.CurrentDomain.GetAssemblies().First(k => k.FullName.Contains("HybridLock"));
            var version = ass.GetCustomAttribute <AssemblyFileVersionAttribute>().Version;
            var result  = BenchmarkRunnerCore.Run(r, _ => new InProcessToolchain(false));

            foreach (var c in MarkdownExporter.GitHub.ExportToFiles(result, BenchmarkDotNet.Loggers.ConsoleLogger.Default))
            {
                var path = Path.GetFullPath($"Benchmarks//{name}_{version}.md");
                System.IO.File.Move(c, path);
                ConsoleLogger.Default.WriteLine($"results at {path}");
            }
            foreach (var c in HtmlExporter.Default.ExportToFiles(result, BenchmarkDotNet.Loggers.ConsoleLogger.Default))
            {
                var path = Path.GetFullPath($"Benchmarks//{name}_{version}.html");
                System.IO.File.Move(c, path);
                ConsoleLogger.Default.WriteLine($"results at {path}");
            }
            var exp = new BenchmarkDotNet.Exporters.Csv.CsvExporter(BenchmarkDotNet.Exporters.Csv.CsvSeparator.Semicolon);

            foreach (var c in exp.ExportToFiles(result, BenchmarkDotNet.Loggers.ConsoleLogger.Default))
            {
                var path = Path.GetFullPath($"Benchmarks//{name}_{version}.csv");
                System.IO.File.Move(c, path);
                ConsoleLogger.Default.WriteLine($"results at {path}");
            }
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(OccurencePerfTests)), t => InProcessToolchain.Instance);
     BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(CalDateTimePerfTests)), t => InProcessToolchain.Instance);
     BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(SerializationPerfTests)), t => InProcessToolchain.Instance);
     BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(ThroughputTests)), t => InProcessToolchain.Instance);
 }
Ejemplo n.º 3
0
        public static void Main()
        {
            var bench   = BenchmarkConverter.TypeToBenchmarks(typeof(AsTaskBench));
            var summary = BenchmarkRunnerCore.Run(bench, _ => InProcessToolchain.Instance);

            MarkdownExporter.Console.ExportToLog(summary, ConsoleLogger.Default);
        }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     //BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(OccurencePerfTests)), t => InProcessToolchain.Instance);
     BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(CalDateTimePerfTests)), t => InProcessToolchain.Instance);
     //BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(SerializationPerfTests)), t => InProcessToolchain.Instance);
     //var c = new CalDateTimePerfTests();
     //c.EmptyTzidToTzid();
 }
Ejemplo n.º 5
0
        private static void RunCore(Type benchmarkType, CompetitionState competitionState)
        {
            var logger     = competitionState.Logger;
            var runOptions = competitionState.Options.RunOptions;

            Code.InRange(
                runOptions.MaxRunsAllowed,
                CompetitionRunMode.MaxRunsAllowedCharacteristic.FullId,
                0, MaxRunLimit);

            while (competitionState.RunsLeft > 0)
            {
                competitionState.PrepareForRun();

                var run          = competitionState.RunNumber;
                var runsExpected = competitionState.RunNumber + competitionState.RunsLeft;
                var runMessage   = competitionState.RunLimitExceeded
                                        ? $"Run {run}, total runs (expected): {runsExpected} (rerun limit exceeded, last run)"
                                        : $"Run {run}, total runs (expected): {runsExpected}";

                using (BeginLogImportant(competitionState.Config))
                {
                    logger.WriteSeparatorLine(runMessage);
                }

                // TODO: toolchainProvider to base (???).
                Func <Job, IToolchain> toolchainProvider = j => j.Infrastructure?.Toolchain ?? InProcessToolchain.Instance;

                // Running the benchmark
                var summary = BenchmarkRunnerCore.Run(
                    BenchmarkConverter.TypeToBenchmarks(benchmarkType, competitionState.Config),
                    competitionState.Config,
                    toolchainProvider);
                competitionState.RunCompleted(summary);

                // Dump messages if analysis was not run and there is a validation analyser.
                if (summary.HasCriticalValidationErrors)
                {
                    var validationAnalyser = competitionState.Config
                                             .GetAnalysers()
                                             .OfType <ValidatorMessagesAnalyser>()
                                             .FirstOrDefault();
                    validationAnalyser?.Analyse(summary);
                }

                if (competitionState.HasCriticalErrorsInRun)
                {
                    competitionState.Logger.WriteVerboseHint("Breaking competition execution. High severity error occured.");
                    break;
                }

                if (competitionState.RunLimitExceeded)
                {
                    break;
                }

                if (competitionState.RunsLeft > 0)
                {
                    competitionState.Logger.WriteVerboseHint($"Rerun requested. Runs left: {competitionState.RunsLeft}.");
                }
            }

            if (competitionState.RunLimitExceeded && competitionState.RunsLeft > 0)
            {
                competitionState.WriteMessage(
                    MessageSource.Runner, MessageSeverity.TestError,
                    $"The benchmark run limit ({runOptions.MaxRunsAllowed} runs(s)) exceeded, check log for details.");
            }
            else if (competitionState.RunNumber > 1)
            {
                competitionState.WriteMessage(
                    MessageSource.Runner, MessageSeverity.Warning,
                    $"The benchmark was run {competitionState.RunNumber} time(s), check log for details.");
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var summary = BenchmarkRunnerCore.Run(BenchmarkConverter.TypeToBenchmarks(typeof(StackTesting)), t => InProcessToolchain.Instance);

            Console.Read();
        }
Ejemplo n.º 7
0
        private static void RunCore(CompetitionState competitionState, IMessageLogger messageLogger)
        {
            var logger     = competitionState.Logger;
            var runOptions = competitionState.Options.RunOptions;

            Code.InRange(
                runOptions.MaxRunsAllowed,
                CompetitionRunMode.MaxRunsAllowedCharacteristic.FullId,
                0, MaxRunLimit);

            while (competitionState.RunsLeft > 0)
            {
                competitionState.PrepareForRun();

                LogCompetitionRunHeader(competitionState);

                // Running the benchmark
                var benchmarkType = competitionState.BenchmarkType;
                var runInfo       = _typeToBenchmarkHack(
                    benchmarkType, benchmarkType.GetMethods(), new ReadOnlyConfig(competitionState.Config));
                var summary = BenchmarkRunnerCore.Run(
                    runInfo,
                    j => j.Infrastructure?.Toolchain ?? InProcessToolchain.Instance);
                competitionState.RunCompleted(summary);

                // Dump messages if analysis was not run and there is a validation analyser.
                if (summary.HasCriticalValidationErrors)
                {
                    var validationAnalyser = competitionState.Config
                                             .GetAnalysers()
                                             .OfType <ValidatorMessagesAnalyser>()
                                             .FirstOrDefault();
                    validationAnalyser?.Analyse(summary);
                }

                if (competitionState.HasCriticalErrorsInRun)
                {
                    logger.WriteHintLine("Breaking competition execution. High severity error occured.");
                    break;
                }

                if (competitionState.RunLimitExceeded)
                {
                    break;
                }

                if (competitionState.RunsLeft > 0)
                {
                    logger.WriteHintLine($"Rerun requested. Runs left: {competitionState.RunsLeft}.");
                }
            }

            if (competitionState.RunLimitExceeded && competitionState.RunsLeft > 0)
            {
                messageLogger.WriteTestErrorMessage(
                    $"The benchmark run limit ({runOptions.MaxRunsAllowed} runs(s)) exceeded, check log for details.");
            }
            else if (competitionState.RunNumber > 1)
            {
                messageLogger.WriteWarningMessage(
                    $"The benchmark was run {competitionState.RunNumber} time(s), check log for details.");
            }
        }
 public void Benchmark_Now_against_DateTimeOffset()
 {
     BenchmarkRunnerCore.Run(
         BenchmarkConverter.TypeToBenchmarks(typeof(PreciseDateTimeBenchmark_Now)),
         job => new InProcessToolchain(false));
 }