Permalink
Browse files

Add parsing tests to compiler benchmarks (#31033)

Adds support for testing parsing to the compiler benchmark suite and
refactors the whole suite to make it smaller and simpler.
  • Loading branch information...
agocke committed Nov 8, 2018
1 parent e20ee16 commit 5ba6a80fb041d41839d7bb93a4ae6f20b1ce4a2a

This file was deleted.

Oops, something went wrong.
@@ -22,7 +22,7 @@ public IgnoreReleaseOnly()
Add(DefaultConfig.Instance.GetExporters().ToArray());
Add(DefaultConfig.Instance.GetColumnProviders().ToArray());
Add(MemoryDiagnoser.Default);
Add(Job.Core);
Add(Job.Core.WithGcServer(true));
}
}
@@ -39,7 +39,7 @@ public static void Main(string[] args)
// to communicate information is pass by environment variable
Environment.SetEnvironmentVariable(Helpers.TestProjectEnvVarName, projectPath);
_ = BenchmarkRunner.Run<EmitBenchmark>(config);
_ = BenchmarkRunner.Run<StageBenchmarks>(config);
}
}
}
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Emit;
using Roslyn.Utilities;
using static Microsoft.CodeAnalysis.Compilation;
namespace CompilerBenchmarks
{
public class StageBenchmarks
{
private Compilation _comp;
private CommonPEModuleBuilder _moduleBeingBuilt;
private EmitOptions _options;
private MemoryStream _peStream;
[Benchmark]
public object Parsing()
{
return Helpers.CreateReproCompilation();
}
[GlobalSetup(Target = nameof(CompileMethodsAndEmit))]
public void LoadCompilation()
{
_peStream = new MemoryStream();
_comp = Helpers.CreateReproCompilation();
// Call GetDiagnostics to force declaration symbol binding to finish
_ = _comp.GetDiagnostics();
}
[Benchmark]
public object CompileMethodsAndEmit()
{
_peStream.Position = 0;
return _comp.Emit(_peStream);
}
[GlobalSetup(Target = nameof(SerializeMetadata))]
public void CompileMethods()
{
LoadCompilation();
_options = EmitOptions.Default.WithIncludePrivateMembers(true);
bool embedPdb = _options.DebugInformationFormat == DebugInformationFormat.Embedded;
var diagnostics = DiagnosticBag.GetInstance();
_moduleBeingBuilt = _comp.CheckOptionsAndCreateModuleBuilder(
diagnostics,
manifestResources: null,
_options,
debugEntryPoint: null,
sourceLinkStream: null,
embeddedTexts: null,
testData: null,
cancellationToken: default);
bool success = false;
success = _comp.CompileMethods(
_moduleBeingBuilt,
emittingPdb: embedPdb,
emitMetadataOnly: _options.EmitMetadataOnly,
emitTestCoverageData: _options.EmitTestCoverageData,
diagnostics: diagnostics,
filterOpt: null,
cancellationToken: default);
_comp.GenerateResourcesAndDocumentationComments(
_moduleBeingBuilt,
xmlDocumentationStream: null,
win32ResourcesStream: null,
_options.OutputNameOverride,
diagnostics,
cancellationToken: default);
_comp.ReportUnusedImports(null, diagnostics, default);
_moduleBeingBuilt.CompilationFinished();
diagnostics.Free();
}
[Benchmark]
public object SerializeMetadata()
{
var diagnostics = DiagnosticBag.GetInstance();
_comp.SerializeToPeStream(
_moduleBeingBuilt,
new SimpleEmitStreamProvider(_peStream),
metadataPEStreamProvider: null,
pdbStreamProvider: null,
testSymWriterFactory: null,
diagnostics,
metadataOnly: _options.EmitMetadataOnly,
includePrivateMembers: _options.IncludePrivateMembers,
emitTestCoverageData: _options.EmitTestCoverageData,
pePdbFilePath: _options.PdbFilePath,
privateKeyOpt: null,
cancellationToken: default);
diagnostics.Free();
return _peStream;
}
}
}

0 comments on commit 5ba6a80

Please sign in to comment.