Browse Source

PoC for memory benchmark

christophwille/membench
Christoph Wille 2 years ago
parent
commit
f6f5a9fe5a
  1. 31
      ILSpy.Benchmarks.sln
  2. 19
      ILSpy.Benchmarks/ILSpy.Benchmarks.csproj
  3. 46
      ILSpy.Benchmarks/Program.cs

31
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

19
ILSpy.Benchmarks/ILSpy.Benchmarks.csproj

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj" />
</ItemGroup>
</Project>

46
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<T> -> 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);
}
}
}
Loading…
Cancel
Save