<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Properties;

namespace BenchmarkDotNet.Running
{
    public class BenchmarkSwitcher
    {
        private readonly ConsoleLogger logger = new ConsoleLogger();
        private readonly TypeParser typeParser;

        public BenchmarkSwitcher(Type[] types)
        {
            foreach (var type in types.Where(type => !type.ContainsRunnableBenchmarks()).ToArray())
            {
                logger.WriteLineError($"Type {type} is invalid. Only public, non-generic (closed generic types with public parameterless ctors are supported), non-abstract, non-sealed types with public instance [Benchmark] method(s) are supported.");
            }

            typeParser = new TypeParser(types.Where(type => type.ContainsRunnableBenchmarks()).ToArray(), logger);
        }

        public BenchmarkSwitcher(Assembly assembly)
        {
            typeParser = new TypeParser(assembly.GetRunnableBenchmarks(), logger);
        }

        public static BenchmarkSwitcher FromTypes(Type[] types) => new BenchmarkSwitcher(types);

        public static BenchmarkSwitcher FromAssembly(Assembly assembly) => new BenchmarkSwitcher(assembly);

        /// <summary>
        /// Run all available benchmarks.
        /// </summary>
        public IEnumerable<Summary> RunAll() => Run(new[] { "*" });

        /// <summary>
        /// Run all available benchmarks and join them to a single summary
        /// </summary>
        public Summary RunAllJoined() => Run(new[] { "*", "--join" }).Single();

        public IEnumerable<Summary> Run(string[] args = null, IConfig config = null)
        {
            args = typeParser.ReadArgumentList(args ?? Array.Empty<string>());
            return RunBenchmarks(args, config);
        }

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

            if (ShouldDisplayOptions(args))<commit_msg>add FromAssemblyAndTypes method to make it possible to auto-detect all benchmarks from given assembly and merge them with generic benchmarks<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Properties;

namespace BenchmarkDotNet.Running
{
    public class BenchmarkSwitcher
    {
        private readonly ConsoleLogger logger = new ConsoleLogger();
        private readonly TypeParser typeParser;

        public BenchmarkSwitcher(Type[] types)
        {
            foreach (var type in types.Where(type => !type.ContainsRunnableBenchmarks()).ToArray())
            {
                logger.WriteLineError($"Type {type} is invalid. Only public, non-generic (closed generic types with public parameterless ctors are supported), non-abstract, non-sealed types with public instance [Benchmark] method(s) are supported.");
            }

            typeParser = new TypeParser(types.Where(type => type.ContainsRunnableBenchmarks()).ToArray(), logger);
        }

        public BenchmarkSwitcher(Assembly assembly)
        {
            typeParser = new TypeParser(assembly.GetRunnableBenchmarks(), logger);
        }

        public static BenchmarkSwitcher FromTypes(Type[] types) => new BenchmarkSwitcher(types);

        public static BenchmarkSwitcher FromAssembly(Assembly assembly) => new BenchmarkSwitcher(assembly);

        public static BenchmarkSwitcher FromAssemblyAndTypes(Assembly assembly, Type[] types) 
            => new BenchmarkSwitcher(assembly.GetRunnableBenchmarks().Concat(types).ToArray());

        /// <summary>
        /// Run all available benchmarks.
        /// </summary>
        public IEnumerable<Summary> RunAll() => Run(new[] { "*" });

        /// <summary>
        /// Run all available benchmarks and join them to a single summary
        /// </summary>
        public Summary RunAllJoined() => Run(new[] { "*", "--join" }).Single();

        public IEnumerable<Summary> Run(string[] args = null, IConfig config = null)
        {
            args = typeParser.ReadArgumentList(args ?? Array.Empty<string>());
            return RunBenchmarks(args, config);
        }

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

            if (ShouldDisplayOptions(args))
{'fraction_non_alphanumeric': 0.10109452736318408, 'fraction_numerical': 0.0, 'mean_word_length': 3.072933549432739, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6123526', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1260, 'n_words': 347}