예제 #1
0
        internal static string Generate(Benchmark benchmark)
        {
            var provider = GetDeclarationsProvider(benchmark.Target);

            string text = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt")).
                          Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke).
                          Replace("$TargetTypeNamespace$", provider.TargetTypeNamespace).
                          Replace("$TargetMethodReturnTypeNamespace$", provider.TargetMethodReturnTypeNamespace).
                          Replace("$TargetTypeName$", provider.TargetTypeName).
                          Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate).
                          Replace("$TargetMethodDelegateType$", provider.TargetMethodDelegateType).
                          Replace("$IdleMethodDelegateType$", provider.IdleMethodDelegateType).
                          Replace("$IdleMethodReturnType$", provider.IdleMethodReturnType).
                          Replace("$SetupMethodName$", provider.SetupMethodName).
                          Replace("$CleanupMethodName$", provider.CleanupMethodName).
                          Replace("$IdleImplementation$", provider.IdleImplementation).
                          Replace("$HasReturnValue$", provider.HasReturnValue).
                          Replace("$AdditionalLogic$", benchmark.Target.AdditionalLogic).
                          Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
                          Replace("$ParamsContent$", GetParamsContent(benchmark)).
                          Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
                          Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)).
                          ToString();

            text = Unroll(text, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));

            return(text);
        }
예제 #2
0
        internal static string Generate(Benchmark benchmark)
        {
            var provider = GetDeclarationsProvider(benchmark.Target);

            (bool useShadowCopy, string shadowCopyFolderPath) = GetShadowCopySettings();

            string text = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt")).
                          Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke).
                          Replace("$TargetTypeNamespace$", provider.TargetTypeNamespace).
                          Replace("$TargetMethodReturnTypeNamespace$", provider.TargetMethodReturnTypeNamespace).
                          Replace("$TargetTypeName$", provider.TargetTypeName).
                          Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate).
                          Replace("$TargetMethodReturnType$", provider.TargetMethodReturnTypeName).
                          Replace("$IdleMethodReturnTypeName$", provider.IdleMethodReturnTypeName).
                          Replace("$GlobalSetupMethodName$", provider.GlobalSetupMethodName).
                          Replace("$GlobalCleanupMethodName$", provider.GlobalCleanupMethodName).
                          Replace("$IterationSetupMethodName$", provider.IterationSetupMethodName).
                          Replace("$IterationCleanupMethodName$", provider.IterationCleanupMethodName).
                          Replace("$IdleImplementation$", provider.IdleImplementation).
                          Replace("$ExtraDefines$", provider.ExtraDefines).
                          Replace("$ConsumeField$", provider.ConsumeField).
                          Replace("$AdditionalLogic$", benchmark.Target.AdditionalLogic).
                          Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
                          Replace("$ParamsContent$", GetParamsContent(benchmark)).
                          Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
                          Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)).
                          Replace("$ShadowCopyDefines$", useShadowCopy ? "#define SHADOWCOPY" : null).
                          Replace("$ShadowCopyFolderPath$", shadowCopyFolderPath).
                          Replace("$Ref$", provider.UseRefKeyword ? "ref" : null).
                          ToString();

            text = Unroll(text, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));

            return(text);
        }
        internal static string Generate(Benchmark benchmark)
        {
            var provider = GetDeclarationsProvider(benchmark.Target);

            string text = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt")).
                Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke).
                Replace("$TargetTypeNamespace$", provider.TargetTypeNamespace).
                Replace("$TargetMethodReturnTypeNamespace$", provider.TargetMethodReturnTypeNamespace).
                Replace("$TargetTypeName$", provider.TargetTypeName).
                Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate).
                Replace("$TargetMethodDelegateType$", provider.TargetMethodDelegateType).
                Replace("$IdleMethodDelegateType$", provider.IdleMethodDelegateType).
                Replace("$IdleMethodReturnType$", provider.IdleMethodReturnType).
                Replace("$SetupMethodName$", provider.SetupMethodName).
                Replace("$CleanupMethodName$", provider.CleanupMethodName).
                Replace("$IdleImplementation$", provider.IdleImplementation).
                Replace("$HasReturnValue$", provider.HasReturnValue).
                Replace("$AdditionalLogic$", benchmark.Target.AdditionalLogic).
                Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
                Replace("$ParamsContent$", GetParamsContent(benchmark)).
                Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
                Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)). 
                ToString();

            text = Unroll(text, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));

            return text;
        }
예제 #4
0
        internal static string Generate(Benchmark benchmark, IConfig config)
        {
            var provider = GetDeclarationsProvider(benchmark.Target);

            (bool useShadowCopy, string shadowCopyFolderPath) = GetShadowCopySettings();

            string passArguments = GetPassArguments(benchmark);

            string text = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt")).
                          Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke).
                          Replace("$TargetTypeNamespace$", provider.TargetTypeNamespace).
                          Replace("$TargetMethodReturnTypeNamespace$", provider.TargetMethodReturnTypeNamespace).
                          Replace("$TargetTypeName$", provider.TargetTypeName).
                          Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate).
                          Replace("$TargetMethodReturnType$", provider.TargetMethodReturnTypeName).
                          Replace("$IdleMethodReturnTypeName$", provider.IdleMethodReturnTypeName).
                          Replace("$GlobalSetupMethodName$", provider.GlobalSetupMethodName).
                          Replace("$GlobalCleanupMethodName$", provider.GlobalCleanupMethodName).
                          Replace("$IterationSetupMethodName$", provider.IterationSetupMethodName).
                          Replace("$IterationCleanupMethodName$", provider.IterationCleanupMethodName).
                          Replace("$IdleImplementation$", provider.IdleImplementation).
                          Replace("$ExtraDefines$", provider.ExtraDefines).
                          Replace("$ConsumeField$", provider.ConsumeField).
                          Replace("$AdditionalLogic$", benchmark.Target.AdditionalLogic).
                          Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark)).
                          Replace("$ParamsContent$", GetParamsContent(benchmark)).
                          Replace("$ArgumentsDefinition$", GetArgumentsDefinition(benchmark)).
                          Replace("$DeclareArgumentFields$", GetDeclareArgumentFields(benchmark)).
                          Replace("$InitializeArgumentFields$", GetInitializeArgumentFields(benchmark)).
                          Replace("$LoadArguments$", GetLoadArguments(benchmark)).
                          Replace("$PassArguments$", passArguments).
                          Replace("$ExtraAttribute$", GetExtraAttributes(benchmark.Target)).
                          Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark)).
                          Replace("$ShadowCopyDefines$", useShadowCopy ? "#define SHADOWCOPY" : null).
                          Replace("$ShadowCopyFolderPath$", shadowCopyFolderPath).
                          Replace("$Ref$", provider.UseRefKeyword ? "ref" : null).
                          Replace("$MeasureGcStats$", config.HasMemoryDiagnoser() ? "true" : "false").
                          Replace("$DiassemblerEntryMethodName$", DisassemblerConstants.DiassemblerEntryMethodName).
                          Replace("$TargetMethodCall$", provider.GetTargetMethodCall(passArguments)).
                          ToString();

            text = Unroll(text, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));

            return(text);
        }
예제 #5
0
        internal static string Generate(BuildPartition buildPartition)
        {
            (bool useShadowCopy, string shadowCopyFolderPath) = GetShadowCopySettings();

            var benchmarksCode = new List <string>(buildPartition.Benchmarks.Length);

            var extraDefines                    = new List <string>();
            var targetTypeNamespaces            = new HashSet <string>();
            var targetMethodReturnTypeNamespace = new HashSet <string>();
            var additionalLogic                 = new HashSet <string>();

            foreach (var buildInfo in buildPartition.Benchmarks)
            {
                var benchmark = buildInfo.Benchmark;

                var provider = GetDeclarationsProvider(benchmark.Target);

                string passArguments = GetPassArguments(benchmark);

                extraDefines.Add($"{provider.ExtraDefines}_{buildInfo.Id}");

                AddNonEmptyUnique(targetTypeNamespaces, provider.TargetTypeNamespace);
                AddNonEmptyUnique(targetMethodReturnTypeNamespace, provider.TargetMethodReturnTypeNamespace);
                AddNonEmptyUnique(additionalLogic, benchmark.Target.AdditionalLogic);

                string benchmarkTypeCode = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkType.txt"))
                                           .Replace("$ID$", buildInfo.Id.ToString())
                                           .Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke)
                                           .Replace("$TargetTypeName$", provider.TargetTypeName)
                                           .Replace("$TargetMethodDelegate$", provider.TargetMethodDelegate)
                                           .Replace("$TargetMethodReturnType$", provider.TargetMethodReturnTypeName)
                                           .Replace("$IdleMethodReturnTypeName$", provider.IdleMethodReturnTypeName)
                                           .Replace("$GlobalSetupMethodName$", provider.GlobalSetupMethodName)
                                           .Replace("$GlobalCleanupMethodName$", provider.GlobalCleanupMethodName)
                                           .Replace("$IterationSetupMethodName$", provider.IterationSetupMethodName)
                                           .Replace("$IterationCleanupMethodName$", provider.IterationCleanupMethodName)
                                           .Replace("$IdleImplementation$", provider.IdleImplementation)
                                           .Replace("$ConsumeField$", provider.ConsumeField)
                                           .Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark))
                                           .Replace("$ParamsContent$", GetParamsContent(benchmark))
                                           .Replace("$ArgumentsDefinition$", GetArgumentsDefinition(benchmark))
                                           .Replace("$DeclareArgumentFields$", GetDeclareArgumentFields(benchmark))
                                           .Replace("$InitializeArgumentFields$", GetInitializeArgumentFields(benchmark)).Replace("$LoadArguments$", GetLoadArguments(benchmark))
                                           .Replace("$PassArguments$", passArguments)
                                           .Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark))
                                           .Replace("$Ref$", provider.UseRefKeyword ? "ref" : null)
                                           .Replace("$MeasureGcStats$", buildInfo.Config.HasMemoryDiagnoser() ? "true" : "false")
                                           .Replace("$Encoding$", buildInfo.Config.Encoding.ToTemplateString())
                                           .Replace("$DiassemblerEntryMethodName$", DisassemblerConstants.DiassemblerEntryMethodName)
                                           .Replace("$TargetMethodCall$", provider.GetTargetMethodCall(passArguments)).ToString();

                benchmarkTypeCode = Unroll(benchmarkTypeCode, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance));

                benchmarksCode.Add(benchmarkTypeCode);
            }

            if (buildPartition.IsCoreRT)
            {
                extraDefines.Add("#define CORERT");
            }

            string benchmarkProgramContent = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt"))
                                             .Replace("$ShadowCopyDefines$", useShadowCopy ? "#define SHADOWCOPY" : null).Replace("$ShadowCopyFolderPath$", shadowCopyFolderPath)
                                             .Replace("$ExtraDefines$", string.Join(Environment.NewLine, extraDefines))
                                             .Replace("$TargetTypeNamespace$", string.Join(Environment.NewLine, targetTypeNamespaces))
                                             .Replace("$TargetMethodReturnTypeNamespace$", string.Join(Environment.NewLine, targetMethodReturnTypeNamespace))
                                             .Replace("$AdditionalLogic$", string.Join(Environment.NewLine, additionalLogic))
                                             .Replace("$DerivedTypes$", string.Join(Environment.NewLine, benchmarksCode))
                                             .Replace("$ExtraAttribute$", GetExtraAttributes(buildPartition.RepresentativeBenchmark.Target))
                                             .Replace("$CoreRtSwitch$", GetCoreRtSwitch(buildPartition))
                                             .ToString();

            return(benchmarkProgramContent);
        }
예제 #6
0
        internal static string Generate(BuildPartition buildPartition)
        {
            (bool useShadowCopy, string shadowCopyFolderPath) = GetShadowCopySettings();

            var benchmarksCode = new List <string>(buildPartition.Benchmarks.Length);

            var extraDefines    = new List <string>();
            var additionalLogic = new HashSet <string>();

            foreach (var buildInfo in buildPartition.Benchmarks)
            {
                var benchmark = buildInfo.BenchmarkCase;

                var provider = GetDeclarationsProvider(benchmark.Descriptor);

                string passArguments = GetPassArguments(benchmark);

                string compilationId = $"{provider.ReturnsDefinition}_{buildInfo.Id}";

                AddNonEmptyUnique(additionalLogic, benchmark.Descriptor.AdditionalLogic);

                string benchmarkTypeCode = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkType.txt"))
                                           .Replace("$ID$", buildInfo.Id.ToString())
                                           .Replace("$OperationsPerInvoke$", provider.OperationsPerInvoke)
                                           .Replace("$WorkloadTypeName$", provider.WorkloadTypeName)
                                           .Replace("$WorkloadMethodDelegate$", provider.WorkloadMethodDelegate(passArguments))
                                           .Replace("$WorkloadMethodReturnType$", provider.WorkloadMethodReturnTypeName)
                                           .Replace("$WorkloadMethodReturnTypeModifiers$", provider.WorkloadMethodReturnTypeModifiers)
                                           .Replace("$OverheadMethodReturnTypeName$", provider.OverheadMethodReturnTypeName)
                                           .Replace("$GlobalSetupMethodName$", provider.GlobalSetupMethodName)
                                           .Replace("$GlobalCleanupMethodName$", provider.GlobalCleanupMethodName)
                                           .Replace("$IterationSetupMethodName$", provider.IterationSetupMethodName)
                                           .Replace("$IterationCleanupMethodName$", provider.IterationCleanupMethodName)
                                           .Replace("$OverheadImplementation$", provider.OverheadImplementation)
                                           .Replace("$ConsumeField$", provider.ConsumeField)
                                           .Replace("$JobSetDefinition$", GetJobsSetDefinition(benchmark))
                                           .Replace("$ParamsContent$", GetParamsContent(benchmark))
                                           .Replace("$ArgumentsDefinition$", GetArgumentsDefinition(benchmark))
                                           .Replace("$DeclareArgumentFields$", GetDeclareArgumentFields(benchmark))
                                           .Replace("$InitializeArgumentFields$", GetInitializeArgumentFields(benchmark)).Replace("$LoadArguments$", GetLoadArguments(benchmark))
                                           .Replace("$PassArguments$", passArguments)
                                           .Replace("$EngineFactoryType$", GetEngineFactoryTypeName(benchmark))
                                           .Replace("$MeasureExtraStats$", buildInfo.Config.HasExtraStatsDiagnoser() ? "true" : "false")
                                           .Replace("$DisassemblerEntryMethodName$", DisassemblerConstants.DisassemblerEntryMethodName)
                                           .Replace("$WorkloadMethodCall$", provider.GetWorkloadMethodCall(passArguments))
                                           .RemoveRedundantIfDefines(compilationId);

                benchmarkTypeCode = Unroll(benchmarkTypeCode, benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvironmentResolver.Instance));

                benchmarksCode.Add(benchmarkTypeCode);
            }

            if (buildPartition.IsNativeAot)
            {
                extraDefines.Add("#define NATIVEAOT");
            }
            else if (buildPartition.IsNetFramework)
            {
                extraDefines.Add("#define NETFRAMEWORK");
            }
            else if (buildPartition.IsWasm)
            {
                extraDefines.Add("#define WASM");
            }

            if (buildPartition.NoAcknowledgments)
            {
                extraDefines.Add("#define NO_ACK");
            }

            string benchmarkProgramContent = new SmartStringBuilder(ResourceHelper.LoadTemplate("BenchmarkProgram.txt"))
                                             .Replace("$ShadowCopyDefines$", useShadowCopy ? "#define SHADOWCOPY" : null).Replace("$ShadowCopyFolderPath$", shadowCopyFolderPath)
                                             .Replace("$ExtraDefines$", string.Join(Environment.NewLine, extraDefines))
                                             .Replace("$AdditionalLogic$", string.Join(Environment.NewLine, additionalLogic))
                                             .Replace("$DerivedTypes$", string.Join(Environment.NewLine, benchmarksCode))
                                             .Replace("$ExtraAttribute$", GetExtraAttributes(buildPartition.RepresentativeBenchmarkCase.Descriptor))
                                             .Replace("$NativeAotSwitch$", GetNativeAotSwitch(buildPartition))
                                             .ToString();

            return(benchmarkProgramContent);
        }