Skip to content

Commit

Permalink
added benchmark project
Browse files Browse the repository at this point in the history
  • Loading branch information
dd committed Oct 18, 2021
1 parent cd4bdcd commit 4853cd5
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/MethodBoundaryAspect.Fody.Benchmark/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions src/MethodBoundaryAspect.Fody.Benchmark/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers VerifyAssembly="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<MethodBoundaryAspect/>
</Weavers>
26 changes: 26 additions & 0 deletions src/MethodBoundaryAspect.Fody.Benchmark/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="MethodBoundaryAspect" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Fody" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.140" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions src/MethodBoundaryAspect.Fody.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using MethodBoundaryAspect.Fody.Attributes;

namespace MethodBoundaryAspect.Fody.Benchmark
{
public class InvocationBenchmark
{
[Benchmark]
public int MethodCallWithAspect() => TestClass.ExecuteWithAspect(5);

[Benchmark]
public int MethodCallWithoutAspect() => TestClass.ExecuteWithoutAspect(5);
}

public class Program
{
public static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<InvocationBenchmark>();
}
}


class TestClass
{
[TestAspect]
public static int ExecuteWithAspect(int x)
{
var sum = 0;
for (var i = 0; i < 100; i++)
sum += i * x;

return sum;
}

public static int ExecuteWithoutAspect(int x)
{
var sum = 0;
for (var i = 0; i < 100; i++)
sum += i * x;

return sum;
}
}

class TestAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs arg)
{
base.OnEntry(arg);
}

public override void OnExit(MethodExecutionArgs arg)
{
base.OnEntry(arg);
}
}
}
6 changes: 6 additions & 0 deletions src/MethodBoundaryAspect.Fody.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MethodBoundaryAspect.Fody.U
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0C4D4E38-5A54-4A51-A308-1D4FA1AD3A4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MethodBoundaryAspect.Fody.Benchmark", "MethodBoundaryAspect.Fody.Benchmark\MethodBoundaryAspect.Fody.Benchmark.csproj", "{7C147C05-6200-4873-ACBE-771E287C4900}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -83,6 +85,10 @@ Global
{4824FDD3-D225-4812-B75C-C0E455B25B7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4824FDD3-D225-4812-B75C-C0E455B25B7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4824FDD3-D225-4812-B75C-C0E455B25B7A}.Release|Any CPU.Build.0 = Release|Any CPU
{7C147C05-6200-4873-ACBE-771E287C4900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C147C05-6200-4873-ACBE-771E287C4900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C147C05-6200-4873-ACBE-771E287C4900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C147C05-6200-4873-ACBE-771E287C4900}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/MethodBoundaryAspect.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace MethodBoundaryAspect.Fody
/// Optimize weaving: Dont generate code of "OnXXX()" method is empty or not used -> ok
/// Optimize weaving: remove runtime dependency on "MethodBoundaryAspect.Attributes" assembly
/// Optimize weaving: only put arguments in MethodExecutionArgs if they are accessed in "OnXXX()" method
/// Optimize weaving: store GetCurrentMethod() result in static Dictionary in MethodBoundaryAspect with generated id for lookup to prevent reflection penalty
/// Optimize weaving: store GetCurrentMethod() result in static Dictionary in MethodBoundaryAspect with generated id for lookup to prevent reflection penalty -> ok
/// </summary>
public class ModuleWeaver : BaseModuleWeaver
{
Expand Down

0 comments on commit 4853cd5

Please sign in to comment.