diff --git a/ILSpy.Benchmarks.sln b/ILSpy.Benchmarks.sln new file mode 100644 index 000000000..74268354e --- /dev/null +++ b/ILSpy.Benchmarks.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34004.107 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILSpy.Benchmarks", "ILSpy.Benchmarks\ILSpy.Benchmarks.csproj", "{67E4B874-948E-4649-B8B5-4B2ED14C4019}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.Decompiler", "ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj", "{92CEF45B-D9B8-4F3B-957A-FF74E2D8415B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {67E4B874-948E-4649-B8B5-4B2ED14C4019}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67E4B874-948E-4649-B8B5-4B2ED14C4019}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67E4B874-948E-4649-B8B5-4B2ED14C4019}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67E4B874-948E-4649-B8B5-4B2ED14C4019}.Release|Any CPU.Build.0 = Release|Any CPU + {92CEF45B-D9B8-4F3B-957A-FF74E2D8415B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92CEF45B-D9B8-4F3B-957A-FF74E2D8415B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92CEF45B-D9B8-4F3B-957A-FF74E2D8415B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92CEF45B-D9B8-4F3B-957A-FF74E2D8415B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F1EFB7E1-D81D-4E24-BD70-A2D313D4FB8F} + EndGlobalSection +EndGlobal diff --git a/ILSpy.Benchmarks/ILSpy.Benchmarks.csproj b/ILSpy.Benchmarks/ILSpy.Benchmarks.csproj new file mode 100644 index 000000000..6e1c4cefc --- /dev/null +++ b/ILSpy.Benchmarks/ILSpy.Benchmarks.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/ILSpy.Benchmarks/Program.cs b/ILSpy.Benchmarks/Program.cs new file mode 100644 index 000000000..025299f18 --- /dev/null +++ b/ILSpy.Benchmarks/Program.cs @@ -0,0 +1,46 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Diagnostics.Windows.Configs; + +using ICSharpCode.Decompiler.CSharp; +using ICSharpCode.Decompiler; + +using ICSharpCode.Decompiler.TypeSystem; +using BenchmarkDotNet.Running; + +namespace ILSpy.Benchmarks +{ + [ShortRunJob] + // [NativeMemoryProfiler] // needs elevation, see also https://benchmarkdotnet.org/articles/configs/diagnosers.html#sample-intronativememory + [MemoryDiagnoser] + public class DecompilerBenchmarks + { + /* + | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | + |-------------------- |---------:|---------:|---------:|----------:|---------:|---------:|----------:| + | SimpleDecompilation | 46.69 ms | 26.13 ms | 1.432 ms | 2090.9091 | 909.0909 | 272.7273 | 15.33 MB | + */ + [Benchmark] + public void SimpleDecompilation() + { + string testAssemblyPath = typeof(CSharpDecompiler).Assembly.Location; + var decompiler = new CSharpDecompiler(testAssemblyPath, new DecompilerSettings()); + + // ICSharpCode.Decompiler.Util.Empty -> translates to `n, where n is the # of generic parameters + var nameOfGenericType = new FullTypeName("ICSharpCode.Decompiler.Util.Empty`1"); + string decompiledStuff = decompiler.DecompileTypeAsString(nameOfGenericType); + + //var nameOfUniResolver = new FullTypeName("ICSharpCode.Decompiler.Metadata.UniversalAssemblyResolver"); + //ITypeDefinition typeInfo = decompiler.TypeSystem.FindType(nameOfUniResolver).GetDefinition(); + //var tokenOfFirstMethod = typeInfo.Methods.First().MetadataToken; + //decompiledStuff = decompiler.DecompileAsString(tokenOfFirstMethod); + } + } + + internal class Program + { + static void Main(string[] args) + { + var summary = BenchmarkRunner.Run(typeof(Program).Assembly); + } + } +}