Created
February 24, 2018 18:34
-
-
Save svick/d6f73009dd90db4d562e44ac549d2c96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFramework>netcoreapp2.0</TargetFramework> | |
| <LangVersion>latest</LangVersion> | |
| </PropertyGroup> | |
| <ItemGroup> | |
| <PackageReference Include="BenchmarkDotNet" Version="0.10.11" /> | |
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" /> | |
| </ItemGroup> | |
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Configs; | |
| using BenchmarkDotNet.Diagnosers; | |
| using BenchmarkDotNet.Running; | |
| using Microsoft.CodeAnalysis; | |
| using Microsoft.CodeAnalysis.CSharp; | |
| using Microsoft.CodeAnalysis.Emit; | |
| using Microsoft.CodeAnalysis.Text; | |
| public class Program | |
| { | |
| static void Main() => BenchmarkRunner.Run<Program>(); | |
| //static void Main() => new Program().Benchmark(); | |
| const string RoslynDir = "/home/svick/roslyn"; | |
| static readonly string UserDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); | |
| List<string> files = Directory.GetFiles($"{RoslynDir}/src/Compilers/CSharp/Portable", "*.cs", SearchOption.AllDirectories) | |
| .Append($"{RoslynDir}/src/Compilers/CSharp/CSharpAnalyzerDriver/CSharpDeclarationComputer.cs") | |
| .ToList(); | |
| List<MetadataReference> references = new[] | |
| { | |
| $"{RoslynDir}/Binaries/Debug/Dlls/CodeAnalysis/ref/Microsoft.CodeAnalysis.dll", | |
| $"{UserDir}/.nuget/packages/system.collections.concurrent/4.3.0/ref/netstandard1.3/System.Collections.Concurrent.dll", | |
| $"{UserDir}/.nuget/packages/system.collections/4.3.0/ref/netstandard1.3/System.Collections.dll", | |
| $"{UserDir}/.nuget/packages/system.collections.immutable/1.3.1/lib/netstandard1.0/System.Collections.Immutable.dll", | |
| $"{UserDir}/.nuget/packages/system.diagnostics.debug/4.3.0/ref/netstandard1.3/System.Diagnostics.Debug.dll", | |
| $"{UserDir}/.nuget/packages/system.diagnostics.fileversioninfo/4.3.0/ref/netstandard1.3/System.Diagnostics.FileVersionInfo.dll", | |
| $"{UserDir}/.nuget/packages/system.diagnostics.tools/4.3.0/ref/netstandard1.0/System.Diagnostics.Tools.dll", | |
| $"{UserDir}/.nuget/packages/system.globalization/4.3.0/ref/netstandard1.3/System.Globalization.dll", | |
| $"{UserDir}/.nuget/packages/system.io.compression/4.3.0/ref/netstandard1.3/System.IO.Compression.dll", | |
| $"{UserDir}/.nuget/packages/system.io/4.3.0/ref/netstandard1.3/System.IO.dll", | |
| $"{UserDir}/.nuget/packages/system.io.filesystem/4.3.0/ref/netstandard1.3/System.IO.FileSystem.dll", | |
| $"{UserDir}/.nuget/packages/system.io.filesystem.primitives/4.3.0/ref/netstandard1.3/System.IO.FileSystem.Primitives.dll", | |
| $"{UserDir}/.nuget/packages/system.linq/4.3.0/ref/netstandard1.0/System.Linq.dll", | |
| $"{UserDir}/.nuget/packages/system.linq.expressions/4.3.0/ref/netstandard1.3/System.Linq.Expressions.dll", | |
| $"{UserDir}/.nuget/packages/system.reflection/4.3.0/ref/netstandard1.3/System.Reflection.dll", | |
| $"{UserDir}/.nuget/packages/system.reflection.extensions/4.3.0/ref/netstandard1.0/System.Reflection.Extensions.dll", | |
| $"{UserDir}/.nuget/packages/system.reflection.metadata/1.4.2/lib/netstandard1.1/System.Reflection.Metadata.dll", | |
| $"{UserDir}/.nuget/packages/system.reflection.primitives/4.3.0/ref/netstandard1.0/System.Reflection.Primitives.dll", | |
| $"{UserDir}/.nuget/packages/system.resources.resourcemanager/4.3.0/ref/netstandard1.0/System.Resources.ResourceManager.dll", | |
| $"{UserDir}/.nuget/packages/system.runtime/4.3.0/ref/netstandard1.3/System.Runtime.dll", | |
| $"{UserDir}/.nuget/packages/system.runtime.extensions/4.3.0/ref/netstandard1.3/System.Runtime.Extensions.dll", | |
| $"{UserDir}/.nuget/packages/system.runtime.handles/4.3.0/ref/netstandard1.3/System.Runtime.Handles.dll", | |
| $"{UserDir}/.nuget/packages/system.runtime.interopservices/4.3.0/ref/netstandard1.3/System.Runtime.InteropServices.dll", | |
| $"{UserDir}/.nuget/packages/system.runtime.numerics/4.3.0/ref/netstandard1.1/System.Runtime.Numerics.dll", | |
| $"{UserDir}/.nuget/packages/system.security.cryptography.algorithms/4.3.0/ref/netstandard1.3/System.Security.Cryptography.Algorithms.dll", | |
| $"{UserDir}/.nuget/packages/system.security.cryptography.encoding/4.3.0/ref/netstandard1.3/System.Security.Cryptography.Encoding.dll", | |
| $"{UserDir}/.nuget/packages/system.security.cryptography.primitives/4.3.0/ref/netstandard1.3/System.Security.Cryptography.Primitives.dll", | |
| $"{UserDir}/.nuget/packages/system.security.cryptography.x509certificates/4.3.0/ref/netstandard1.3/System.Security.Cryptography.X509Certificates.dll", | |
| $"{UserDir}/.nuget/packages/system.text.encoding.codepages/4.3.0/ref/netstandard1.3/System.Text.Encoding.CodePages.dll", | |
| $"{UserDir}/.nuget/packages/system.text.encoding/4.3.0/ref/netstandard1.3/System.Text.Encoding.dll", | |
| $"{UserDir}/.nuget/packages/system.text.encoding.extensions/4.3.0/ref/netstandard1.3/System.Text.Encoding.Extensions.dll", | |
| $"{UserDir}/.nuget/packages/system.threading/4.3.0/ref/netstandard1.3/System.Threading.dll", | |
| $"{UserDir}/.nuget/packages/system.threading.tasks/4.3.0/ref/netstandard1.3/System.Threading.Tasks.dll", | |
| $"{UserDir}/.nuget/packages/system.threading.tasks.parallel/4.3.0/ref/netstandard1.1/System.Threading.Tasks.Parallel.dll", | |
| $"{UserDir}/.nuget/packages/system.valuetuple/4.3.0/lib/netstandard1.0/System.ValueTuple.dll", | |
| $"{UserDir}/.nuget/packages/system.xml.readerwriter/4.3.0/ref/netstandard1.3/System.Xml.ReaderWriter.dll", | |
| $"{UserDir}/.nuget/packages/system.xml.xdocument/4.3.0/ref/netstandard1.3/System.Xml.XDocument.dll", | |
| $"{UserDir}/.nuget/packages/system.xml.xmldocument/4.3.0/ref/netstandard1.3/System.Xml.XmlDocument.dll", | |
| $"{UserDir}/.nuget/packages/system.xml.xpath/4.3.0/ref/netstandard1.3/System.Xml.XPath.dll", | |
| $"{UserDir}/.nuget/packages/system.xml.xpath.xdocument/4.3.0/ref/netstandard1.3/System.Xml.XPath.XDocument.dll" | |
| }.Select(f => MetadataReference.CreateFromFile(f)).ToList<MetadataReference>(); | |
| CSharpCompilation CreateCompilation(DocumentationMode documentationMode) | |
| { | |
| var trees = files.Select(f => | |
| { | |
| using (var stream = File.OpenRead(f)) | |
| { | |
| return SyntaxFactory.ParseSyntaxTree(SourceText.From(stream), new CSharpParseOptions(LanguageVersion.Latest, documentationMode, preprocessorSymbols: new[] { "NETSTANDARD1_3" })); | |
| } | |
| }).ToList(); | |
| return CSharpCompilation.Create( | |
| "Microsoft.CodeAnalysis.CSharp", trees, references, | |
| new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: $"{RoslynDir}/build/Targets/../Strong Name Keys/35MSSharedLib1024.snk", publicSign: true)); | |
| } | |
| [Params(EmitMode.None, EmitMode.Null, EmitMode.NullStream)] | |
| public EmitMode EmitMode { get; set; } | |
| [Params(DocumentationMode.None, DocumentationMode.Parse, DocumentationMode.Diagnose)] | |
| public DocumentationMode DocumentationMode { get; set; } | |
| [Benchmark] | |
| public void Benchmark() | |
| { | |
| var compilation = CreateCompilation(DocumentationMode); | |
| foreach (var diag in compilation.GetDiagnostics().Where(d => d.Severity >= DiagnosticSeverity.Error).Take(10)) | |
| Console.WriteLine(diag); | |
| Stream xmlStream; | |
| switch (EmitMode) | |
| { | |
| case EmitMode.None: | |
| return; | |
| case EmitMode.Null: | |
| xmlStream = null; | |
| break; | |
| case EmitMode.NullStream: | |
| xmlStream = Stream.Null; | |
| break; | |
| default: | |
| throw new Exception(); | |
| } | |
| var result = compilation.Emit(Stream.Null, xmlDocumentationStream: xmlStream); | |
| if (!result.Success) | |
| throw new Exception(); | |
| } | |
| } | |
| public enum EmitMode | |
| { | |
| None, | |
| Null, | |
| NullStream | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BenchmarkDotNet=v0.10.11, OS=ubuntu 16.04 | |
| Processor=Intel Xeon CPU E5-2673 v3 2.40GHz, ProcessorCount=1 | |
| .NET Core SDK=2.1.4 | |
| [Host] : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | |
| DefaultJob : .NET Core 2.0.5 (Framework 4.6.0.0), 64bit RyuJIT | |
| Method | EmitMode | DocumentationMode | Mean | Error | StdDev | | |
| ---------- |----------- |------------------ |--------:|---------:|---------:| | |
| Benchmark | None | Diagnose | 12.86 s | 0.1969 s | 0.1842 s | | |
| Benchmark | None | None | 12.19 s | 0.1834 s | 0.1716 s | | |
| Benchmark | None | Parse | 12.52 s | 0.1907 s | 0.1784 s | | |
| Benchmark | Null | Diagnose | 26.37 s | 0.3224 s | 0.3016 s | | |
| Benchmark | Null | None | 25.32 s | 0.2050 s | 0.1601 s | | |
| Benchmark | Null | Parse | 24.91 s | 0.3018 s | 0.2823 s | | |
| Benchmark | NullStream | Diagnose | 26.02 s | 0.3476 s | 0.3252 s | | |
| Benchmark | NullStream | None | 25.36 s | 0.3234 s | 0.3025 s | | |
| Benchmark | NullStream | Parse | 25.33 s | 0.2122 s | 0.1985 s | | |
| // * Hints * | |
| Outliers | |
| Program.Benchmark: Default -> 3 outliers were removed | |
| // * Legends * | |
| EmitMode : Value of the 'EmitMode' parameter | |
| DocumentationMode : Value of the 'DocumentationMode' parameter | |
| Mean : Arithmetic mean of all measurements | |
| Error : Half of 99.9% confidence interval | |
| StdDev : Standard deviation of all measurements | |
| 1 s : 1 Second (1 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment