private IEnumerable <Summary> RunBenchmarks(string[] args, IConfig config)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            var benchmarks = typeParser.MatchingTypesWithMethods(args)
                             .Select(typeWithMethods =>
                                     typeWithMethods.AllMethodsInType
                        ? BenchmarkConverter.TypeToBenchmarks(typeWithMethods.Type, effectiveConfig)
                        : BenchmarkConverter.MethodsToBenchmarks(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig))
                             .ToArray();

            summaries.AddRange(BenchmarkRunner.Run(benchmarks, effectiveConfig, summaryPerType: !join));

            var clockSpan = globalChronometer.GetElapsed();

            BenchmarkRunner.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
示例#2
0
        private IEnumerable <Summary> RunBenchmarks(string[] args)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();
            var config            = ManualConfig.Union(DefaultConfig.Instance, ManualConfig.Parse(args));

            for (int i = 0; i < Types.Length; i++)
            {
                var type = Types[i];
                if (args.Any(arg => type.Name.ToLower().StartsWith(arg.ToLower())) || args.Contains("#" + i) || args.Contains("" + i) || args.Contains("*"))
                {
                    logger.WriteLineHeader("Target type: " + type.Name);
                    summaries.Add(BenchmarkRunner.Run(type, config));
                    logger.NewLine();
                }
            }
            // TODO: move this logic to the RunUrl method
#if CLASSIC
            if (args.Length > 0 && (args[0].StartsWith("http://") || args[0].StartsWith("https://")))
            {
                var url  = args[0];
                Uri uri  = new Uri(url);
                var name = uri.IsFile ? Path.GetFileName(uri.LocalPath) : "URL";
                summaries.Add(BenchmarkRunner.RunUrl(url, config));
            }
#endif
            var clockSpan = globalChronometer.Stop();
            BenchmarkRunner.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
示例#3
0
        [PublicAPI] public IEnumerable <Summary> Run(string[] args = null, IConfig config = null)
        {
            args = args ?? Array.Empty <string>();

            (bool isParsingSuccess, var parsedConfig) = ConfigParser.Parse(args, ConsoleLogger.Default);
            if (!isParsingSuccess)
            {
                return(Enumerable.Empty <Summary>());
            }

            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            var effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, parsedConfig);

            var filteredBenchmarks = typeParser.Filter(effectiveConfig);

            if (filteredBenchmarks.IsEmpty())
            {
                return(Array.Empty <Summary>());
            }

            summaries.AddRange(BenchmarkRunner.Run(filteredBenchmarks, effectiveConfig));

            int totalNumberOfExecutedBenchmarks = summaries.Sum(summary => summary.GetNumberOfExecutedBenchmarks());

            BenchmarkRunner.LogTotalTime(logger, globalChronometer.GetElapsed().GetTimeSpan(), totalNumberOfExecutedBenchmarks, "Global total time");
            return(summaries);
        }
示例#4
0
        public IEnumerable <Summary> Run(string[] args = null, IConfig config = null)
        {
            args = args ?? Array.Empty <string>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            var benchmarks = Filter(effectiveConfig);

            summaries.AddRange(BenchmarkRunner.Run(benchmarks, effectiveConfig, summaryPerType: !join));

            var totalNumberOfExecutedBenchmarks = summaries.Sum(summary => summary.GetNumberOfExecutedBenchmarks());

            BenchmarkRunner.LogTotalTime(logger, globalChronometer.GetElapsed().GetTimeSpan(), totalNumberOfExecutedBenchmarks, "Global total time");
            return(summaries);
        }
示例#5
0
        private IEnumerable <Summary> RunBenchmarks(string[] args, IConfig config)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var  effectiveConfig = ManualConfig.Union(config ?? DefaultConfig.Instance, ManualConfig.Parse(args));
            bool join            = args.Any(arg => arg.EqualsWithIgnoreCase("--join"));

            if (join)
            {
                var typesWithMethods = typeParser.MatchingTypesWithMethods(args);
                var benchmarks       = typesWithMethods.SelectMany(typeWithMethods =>
                                                                   typeWithMethods.AllMethodsInType
                        ? BenchmarkConverter.TypeToBenchmarks(typeWithMethods.Type, effectiveConfig)
                        : BenchmarkConverter.MethodsToBenchmarks(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig)).ToArray();
                summaries.Add(BenchmarkRunner.Run(benchmarks, effectiveConfig));
            }
            else
            {
                foreach (var typeWithMethods in typeParser.MatchingTypesWithMethods(args))
                {
                    logger.WriteLineHeader("Target type: " + typeWithMethods.Type.Name);
                    if (typeWithMethods.AllMethodsInType)
                    {
                        summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, effectiveConfig));
                    }
                    else
                    {
                        summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, typeWithMethods.Methods, effectiveConfig));
                    }
                    logger.WriteLine();
                }
            }

            // TODO: move this logic to the RunUrl method
#if CLASSIC
            if (args.Length > 0 && (args[0].StartsWith("http://") || args[0].StartsWith("https://")))
            {
                var url  = args[0];
                Uri uri  = new Uri(url);
                var name = uri.IsFile ? Path.GetFileName(uri.LocalPath) : "URL";
                summaries.Add(BenchmarkRunner.RunUrl(url, effectiveConfig));
            }
#endif

            var clockSpan = globalChronometer.Stop();
            BenchmarkRunnerCore.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
示例#6
0
        public static IConfig GetFullConfig(Type type, IConfig config)
        {
            config = config ?? DefaultConfig.Instance;
            var configAttribute = type?.GetCustomAttributes <IConfigSource>(true).FirstOrDefault();

            if (configAttribute != null)
            {
                config = ManualConfig.Union(config, configAttribute.Config);
            }
            return(config);
        }
        private static ImmutableConfig GetFullTypeConfig(Type type, IConfig config)
        {
            config = config ?? DefaultConfig.Instance;

            var typeAttributes     = type.GetCustomAttributes(true).OfType <IConfigSource>();
            var assemblyAttributes = type.Assembly.GetCustomAttributes().OfType <IConfigSource>();

            foreach (var configFromAttribute in typeAttributes.Concat(assemblyAttributes))
            {
                config = ManualConfig.Union(config, configFromAttribute.Config);
            }

            return(ImmutableConfigBuilder.Create(config));
        }
 public static ReadOnlyConfig GetFullConfig(Type type, IConfig config)
 {
     config = config ?? DefaultConfig.Instance;
     if (type != null)
     {
         var typeAttributes     = type.GetTypeInfo().GetCustomAttributes(true).OfType <IConfigSource>();
         var assemblyAttributes = type.GetTypeInfo().Assembly.GetCustomAttributes().OfType <IConfigSource>();
         var allAttributes      = typeAttributes.Concat(assemblyAttributes);
         foreach (var configSource in allAttributes)
         {
             config = ManualConfig.Union(config, configSource.Config);
         }
     }
     return(config.AsReadOnly());
 }
示例#9
0
        public static void Main(string[] args)
        {
            var runFarmhashOnly = args.Contains("--farmhash");

            var config32 = ManualConfig.Union(DefaultConfig.Instance, new Config32());
            var config64 = ManualConfig.Union(DefaultConfig.Instance, new Config64());
            if (runFarmhashOnly)
            {
                config32.Add(new NameFilter(name => name.Contains("FarmHash")));
                config64.Add(new NameFilter(name => name.Contains("FarmHash")));
            }

            BenchmarkRunner.Run<HashBenchmark32>(config32);
            BenchmarkRunner.Run<HashBenchmark64>(config64);
        }
示例#10
0
 public static IConfig GetFullConfig(Type type, IConfig config)
 {
     config = config ?? DefaultConfig.Instance;
     if (type != null)
     {
         var typeAttributes     = type.GetCustomAttributes <IConfigSource>(true);
         var assemblyAttributes = type.Assembly().GetCustomAttributes <IConfigSource>(false);
         var allAttributes      = typeAttributes.Concat(assemblyAttributes);
         foreach (var configSource in allAttributes)
         {
             config = ManualConfig.Union(config, configSource.Config);
         }
     }
     return(config);
 }
示例#11
0
        public static ReadOnlyConfig GetFullConfig(Type type, IConfig config)
        {
            config = config ?? DefaultConfig.Instance;
            if (type != null)
            {
                var typeAttributes     = type.GetTypeInfo().GetCustomAttributes(true).OfType <IConfigSource>();
                var assemblyAttributes = type.GetTypeInfo().Assembly.GetCustomAttributes().OfType <IConfigSource>();
                var allAttributes      = typeAttributes.Concat(assemblyAttributes);
                var configs            = allAttributes.Select(attribute => attribute.Config)
                                         .OrderBy(c => c.GetJobs().Count(job => job.Meta.IsMutator)); // configs with mutators must be the ones applied at the end

                foreach (var configFromAttribute in configs)
                {
                    config = ManualConfig.Union(config, configFromAttribute);
                }
            }
            return(config.AsReadOnly());
        }
示例#12
0
        private static ImmutableConfig GetFullMethodConfig(MethodInfo method, ImmutableConfig typeConfig)
        {
            var methodAttributes = method.GetCustomAttributes(true).OfType <IConfigSource>();

            if (!methodAttributes.Any()) // the most common case
            {
                return(typeConfig);
            }

            var config = ManualConfig.Create(typeConfig);

            foreach (var configFromAttribute in methodAttributes)
            {
                config = ManualConfig.Union(config, configFromAttribute.Config);
            }

            return(ImmutableConfigBuilder.Create(config));
        }
示例#13
0
        private IEnumerable <Summary> RunBenchmarks(string[] args)
        {
            var globalChronometer = Chronometer.Start();
            var summaries         = new List <Summary>();

            if (ShouldDisplayOptions(args))
            {
                DisplayOptions();
                return(Enumerable.Empty <Summary>());
            }

            var config = ManualConfig.Union(DefaultConfig.Instance, ManualConfig.Parse(args));

            foreach (var typeWithMethods in typeParser.MatchingTypesWithMethods(args))
            {
                logger.WriteLineHeader("Target type: " + typeWithMethods.Type.Name);
                if (typeWithMethods.AllMethodsInType)
                {
                    summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, config));
                }
                else
                {
                    summaries.Add(BenchmarkRunner.Run(typeWithMethods.Type, typeWithMethods.Methods, config));
                }
                logger.WriteLine();
            }

            // TODO: move this logic to the RunUrl method
#if CLASSIC
            if (args.Length > 0 && (args[0].StartsWith("http://") || args[0].StartsWith("https://")))
            {
                var url  = args[0];
                Uri uri  = new Uri(url);
                var name = uri.IsFile ? Path.GetFileName(uri.LocalPath) : "URL";
                summaries.Add(BenchmarkRunner.RunUrl(url, config));
            }
#endif

            var clockSpan = globalChronometer.Stop();
            BenchmarkRunner.LogTotalTime(logger, clockSpan.GetTimeSpan(), "Global total time");
            return(summaries);
        }
示例#14
0
        /// <summary>Applies <see cref="IConfigSource"/> attribute modifiers.</summary>
        /// <param name="competitionConfig">The competition configuration.</param>
        /// <param name="metadataSource">The metadata source.</param>
        protected virtual void ApplyConfigSources(ManualCompetitionConfig competitionConfig, ICustomAttributeProvider metadataSource)
        {
            var config = new ManualConfig();
            var add    = false;

            if (metadataSource != null)
            {
                foreach (var modifierSource in metadataSource
                         .GetMetadataAttributes <IConfigSource>()
                         .Reverse())
                {
                    config = ManualConfig.Union(config, modifierSource.Config);
                    add    = true;
                }
            }
            if (add)
            {
                competitionConfig.Add(config);
            }
        }