public BenchmarkBuildInfo(BenchmarkCase benchmarkCase, ImmutableConfig config, int id) { BenchmarkCase = benchmarkCase; Config = config; Id = new BenchmarkId(id, benchmarkCase); }
public BenchmarkId(int value, BenchmarkCase benchmarkCase) { Value = value; FullBenchmarkName = FullNameProvider.GetBenchmarkName(benchmarkCase); JobId = benchmarkCase.Job.Id; }
public BenchmarkBuildInfo(BenchmarkCase benchmarkCase, ReadOnlyConfig config, int id) { BenchmarkCase = benchmarkCase; Config = config; Id = new BenchmarkId(id, benchmarkCase); }
public static BenchmarkRunInfo[] SourceToBenchmarks(string source, IConfig config = null) { if (!RuntimeInformation.IsFullFramework) { throw new NotSupportedException("Supported only on Full .NET Framework."); } string benchmarkContent = source; CompilerResults compilerResults; using (var cSharpCodeProvider = new CSharpCodeProvider()) { string directoryName = Path.GetDirectoryName(typeof(BenchmarkCase).Assembly.Location) ?? throw new DirectoryNotFoundException(typeof(BenchmarkCase).Assembly.Location); var compilerParameters = new CompilerParameters( new[] { "mscorlib.dll", "System.dll", "System.Core.dll" }) { CompilerOptions = "/unsafe /optimize", GenerateInMemory = false, OutputAssembly = Path.Combine( directoryName, $"{Path.GetFileNameWithoutExtension(Path.GetTempFileName())}.dll") }; compilerParameters.ReferencedAssemblies.Add(typeof(BenchmarkCase).Assembly.Location); compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters, benchmarkContent); } if (compilerResults.Errors.HasErrors) { var logger = HostEnvironmentInfo.FallbackLogger; compilerResults.Errors.Cast <CompilerError>().ToList().ForEach(error => logger.WriteLineError(error.ErrorText)); return(Array.Empty <BenchmarkRunInfo>()); } var types = compilerResults.CompiledAssembly.GetTypes(); var resultBenchmarks = new List <BenchmarkRunInfo>(); foreach (var type in types) { var runInfo = TypeToBenchmarks(type, config); var benchmarks = runInfo.BenchmarksCases.Select(b => { var target = b.Descriptor; return(BenchmarkCase.Create( new Descriptor(target.Type, target.WorkloadMethod, target.GlobalSetupMethod, target.GlobalCleanupMethod, target.IterationSetupMethod, target.IterationCleanupMethod, target.WorkloadMethodDisplayInfo, benchmarkContent, target.Baseline, target.Categories, target.OperationsPerInvoke), b.Job, b.Parameters, b.Config)); }); resultBenchmarks.Add( new BenchmarkRunInfo(benchmarks.ToArray(), runInfo.Type, runInfo.Config)); } return(resultBenchmarks.ToArray()); }