Skip to content

Commit

Permalink
PoC for memory benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwille committed Aug 17, 2023
1 parent 7c8b497 commit f6f5a9f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ILSpy.Benchmarks.sln
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions ILSpy.Benchmarks/ILSpy.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions ILSpy.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit f6f5a9f

Please sign in to comment.