Пример #1
0
        /// <summary>
        /// Parses an <see cref="IFilter{T}"/>.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>an <see cref="IFilter{T}"/></returns>
        private IFilter <byte[]> ParseFilter(Lexer lexer, string defaultFormat)
        {
            IFilter <byte[]> filter = null;

            if (lexer.MoveNext())
            {
                if (lexer.Current == OpeningPar)
                {
                    filter = ParseFilter(lexer, defaultFormat);
                    lexer.Parse(ClosingPar);
                }
                else
                {
                    string format1;
                    string format2;
                    var    leftAccessor  = ParseAccessor(lexer, defaultFormat, out format1);
                    var    op            = lexer.Parse();
                    var    rightAccessor = ParseAccessor(lexer, defaultFormat, out format2);
                    var    format        = format1 ?? format2;
                    filter = GetFilter(leftAccessor, rightAccessor, format, op);
                }

                if (lexer.Current == Or)
                {
                    var disjunction = new DisjunctionFilter <byte[]>
                    {
                        Filters = new List <IFilter <byte[]> >
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = disjunction;
                }
                else if (lexer.Current == And)
                {
                    var conjunction = new ConjunctionFilter <byte[]>
                    {
                        Filters = new List <IFilter <byte[]> >
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = conjunction;
                }
            }

            return(filter);
        }
Пример #2
0
        /// <summary>
        /// Parses an <see cref="IFilter{T}"/>.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>an <see cref="IFilter{T}"/></returns>
        private IFilter<byte[]> ParseFilter(Lexer lexer, string defaultFormat)
        {
            IFilter<byte[]> filter = null;

            if (lexer.MoveNext())
            {
                if (lexer.Current == OpeningPar)
                {
                    filter = ParseFilter(lexer, defaultFormat);
                    lexer.Parse(ClosingPar);
                }
                else
                {
                    string format1;
                    string format2;
                    var leftAccessor = ParseAccessor(lexer, defaultFormat, out format1);
                    var op = lexer.Parse();
                    var rightAccessor = ParseAccessor(lexer, defaultFormat, out format2);
                    var format = format1 ?? format2;
                    filter = GetFilter(leftAccessor, rightAccessor, format, op);
                }

                if (lexer.Current == Or)
                {
                    var disjunction = new DisjunctionFilter<byte[]>
                    {
                        Filters = new List<IFilter<byte[]>>
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = disjunction;
                }
                else if (lexer.Current == And)
                {
                    var conjunction = new ConjunctionFilter<byte[]>
                    {
                        Filters = new List<IFilter<byte[]>>
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = conjunction;
                }
            }

            return filter;
        }
Пример #3
0
    private static (Summary, IConfig, Job)? ConditionalRun(Type benchmarkType, string[] args, Options options, GCType gcType, Runtime runtime, bool coldStart)
    {
        var config = DefaultConfig.Instance.WithOptions(ConfigOptions.Default);

        //if (Debugger.IsAttached) {
        config = config.WithOptions(ConfigOptions.DisableOptimizationsValidator);
        //}

        if (options.Runners.Count != 0)
        {
            var patterns = CreatePatterns(options.Runners);

            var filters = patterns.Select(runner =>
                                          new NameFilter(runner.IsMatch)
                                          ).Cast <IFilter>();

            var disjunction = new DisjunctionFilter(filters.ToArray());

            config = config.AddFilter(disjunction);
        }

        if (options.DiagnoseCpu)
        {
            config = config.AddDiagnoser(CpuDiagnoser.Default);
        }

        if (options.DiagnoseMemory)
        {
            config = config.AddDiagnoser(MemoryDiagnoser.Default);
        }

        if (options.DiagnoseInlining)
        {
            config = config.AddDiagnoser(new InliningDiagnoser());
        }

        if (options.DiagnoseTailCall)
        {
            config = config.AddDiagnoser(new TailCallDiagnoser());
        }

        if (options.DiagnoseEtw)
        {
            config = config.AddDiagnoser(new EtwProfiler());
        }

        //config.AddJob(Job.InProcess);

        Job job;

        if (Debugger.IsAttached || CurrentOptions.InProcess)
        {
            job = Job.InProcess
                  .WithGcServer(gcType == GCType.Server)
                  .WithRuntime(runtime)
                  .WithEnvironmentVariables(
                new EnvironmentVariable("DOTNET_TieredCompilation", "0"),
                new EnvironmentVariable("BENCHIE_ARGS", string.Join(" ", args))
                )
                  .WithStrategy(coldStart ? RunStrategy.ColdStart : RunStrategy.Throughput);
        }
        else
        {
            job = Job.Default
                  .WithGcServer(gcType == GCType.Server)
                  .WithRuntime(runtime)
                  .WithEnvironmentVariables(
                new EnvironmentVariable("DOTNET_TieredCompilation", "0"),
                new EnvironmentVariable("BENCHIE_ARGS", string.Join(" ", args))
                )
                  .WithStrategy(coldStart ? RunStrategy.ColdStart : RunStrategy.Throughput);
        }

        //if (typeof(TBenchmark) == typeof(Benchmarks.Premultiply)) {
        //	job = job.WithMinIterationCount(60).WithMaxIterationCount(400);
        //}

        string name = $"{gcType}.{runtime}.{(coldStart ? "cold" : "warm")}";

        config = config.AddJob(job);
        config = config.WithArtifactsPath(Path.Combine(config.ArtifactsPath, name));

        {
            List <Type> baseTypes = new();
            Type?       baseType  = benchmarkType;
            while (baseType is not null)
            {
                baseTypes.Add(baseType);
                baseType = baseType.BaseType;
            }

            foreach (var type in baseTypes.ReverseF())
            {
                System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);
            }
        }

        GC.Collect(int.MaxValue, GCCollectionMode.Forced, blocking: true, compacting: true);

        var summary = BenchmarkRunner.Run(benchmarkType, config);

        return(summary, config, job);
    }