Skip to content

Commit

Permalink
Refactor smoke benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Aug 27, 2024
1 parent eba5edb commit fdf3b02
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 323 deletions.
82 changes: 82 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeBasic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples;

[DisassemblyDiagnoser]
public class IntroSmokeBasic
{
[Benchmark] public void Void1() {}
[Benchmark] public void Void2() {}
[Benchmark] public void Void3() {}
[Benchmark] public void Void4() {}

[Benchmark] public byte Byte1() => 0;
[Benchmark] public byte Byte2() => 0;
[Benchmark] public byte Byte3() => 0;
[Benchmark] public byte Byte4() => 0;

[Benchmark] public sbyte Sbyte1() => 0;
[Benchmark] public sbyte Sbyte2() => 0;
[Benchmark] public sbyte Sbyte3() => 0;
[Benchmark] public sbyte Sbyte4() => 0;

[Benchmark] public short Short1() => 0;
[Benchmark] public short Short2() => 0;
[Benchmark] public short Short3() => 0;
[Benchmark] public short Short4() => 0;

[Benchmark] public ushort Ushort1() => 0;
[Benchmark] public ushort Ushort2() => 0;
[Benchmark] public ushort Ushort3() => 0;
[Benchmark] public ushort Ushort4() => 0;

[Benchmark] public int Int1() => 0;
[Benchmark] public int Int2() => 0;
[Benchmark] public int Int3() => 0;
[Benchmark] public int Int4() => 0;

[Benchmark] public uint Uint1() => 0u;
[Benchmark] public uint Uint2() => 0u;
[Benchmark] public uint Uint3() => 0u;
[Benchmark] public uint Uint4() => 0u;

[Benchmark] public bool Bool1() => false;
[Benchmark] public bool Bool2() => false;
[Benchmark] public bool Bool3() => false;
[Benchmark] public bool Bool4() => false;

[Benchmark] public char Char1() => 'a';
[Benchmark] public char Char2() => 'a';
[Benchmark] public char Char3() => 'a';
[Benchmark] public char Char4() => 'a';

[Benchmark] public float Float1() => 0f;
[Benchmark] public float Float2() => 0f;
[Benchmark] public float Float3() => 0f;
[Benchmark] public float Float4() => 0f;

[Benchmark] public double Double1() => 0d;
[Benchmark] public double Double2() => 0d;
[Benchmark] public double Double3() => 0d;
[Benchmark] public double Double4() => 0d;

[Benchmark] public long Long1() => 0L;
[Benchmark] public long Long2() => 0L;
[Benchmark] public long Long3() => 0L;
[Benchmark] public long Long4() => 0L;

[Benchmark] public ulong Ulong1() => 0uL;
[Benchmark] public ulong Ulong2() => 0uL;
[Benchmark] public ulong Ulong3() => 0uL;
[Benchmark] public ulong Ulong4() => 0uL;

[Benchmark] public string String1() => "";
[Benchmark] public string String2() => "";
[Benchmark] public string String3() => "";
[Benchmark] public string String4() => "";

[Benchmark] public object? Object1() => null;
[Benchmark] public object? Object2() => null;
[Benchmark] public object? Object3() => null;
[Benchmark] public object? Object4() => null;
}
139 changes: 139 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeIncrement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples;

[DisassemblyDiagnoser]
public class IntroSmokeIncrement
{
public int Field;

[Benchmark]
public void Increment01()
{
Field++;
}

[Benchmark]
public void Increment02()
{
Field++;
Field++;
}

[Benchmark]
public void Increment03()
{
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment04()
{
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment05()
{
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment06()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment07()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment08()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment09()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment10()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}

[Benchmark]
public void Increment20()
{
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
Field++;
}
}
69 changes: 69 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeValueTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Environments;

namespace BenchmarkDotNet.Samples;

[MemoryDiagnoser, DisassemblyDiagnoser]
public class IntroSmokeValueTypes
{
[Benchmark] public Jit ReturnEnum() => Jit.RyuJit;

[Benchmark] public DateTime ReturnDateTime() => new DateTime();

[Benchmark] public DateTime? ReturnNullableDateTime() => new DateTime();
[Benchmark] public int? ReturnNullableInt() => 0;

public struct StructWithReferencesOnly { public object Ref; }
[Benchmark] public StructWithReferencesOnly ReturnStructWithReferencesOnly() => new StructWithReferencesOnly();

public struct EmptyStruct { }
[Benchmark] public EmptyStruct ReturnEmptyStruct() => new EmptyStruct();

[Benchmark] public ValueTuple<int> ReturnGenericStructOfValueType() => new ValueTuple<int>(0);
[Benchmark] public ValueTuple<object> ReturnGenericStructOfReferenceType() => new ValueTuple<object>(null);

[Benchmark] public ValueTask<int> ReturnValueTaskOfValueType() => new ValueTask<int>(0);
[Benchmark] public ValueTask<object> ReturnValueTaskOfReferenceType() => new ValueTask<object>(result: null);

[Benchmark] public byte ReturnByte() => 0;
public struct Byte1 { public byte _1; }
[Benchmark] public Byte1 ReturnByte1() => new Byte1();
public struct Byte2 { public byte _1, _2; }
[Benchmark] public Byte2 ReturnByte2() => new Byte2();
public struct Byte3 { public byte _1, _2, _3; }
[Benchmark] public Byte3 ReturnByte3() => new Byte3();
public struct Byte4 { public byte _1, _2, _3, _4; }
[Benchmark] public Byte4 ReturnByte4() => new Byte4();

[Benchmark] public short ReturnShort() => 0;
public struct Short1 { public short _1; }
[Benchmark] public Short1 ReturnShort1() => new Short1();
public struct Short2 { public short _1, _2; }
[Benchmark] public Short2 ReturnShort2() => new Short2();
public struct Short3 { public short _1, _2, _3; }
[Benchmark] public Short3 ReturnShort3() => new Short3();
public struct Short4 { public short _1, _2, _3, _4; }
[Benchmark] public Short4 ReturnShort4() => new Short4();

[Benchmark] public int ReturnInt() => 0;
public struct Int1 { public int _1; }
[Benchmark] public Int1 ReturnInt1() => new Int1();
public struct Int2 { public int _1, _2; }
[Benchmark] public Int2 ReturnInt2() => new Int2();
public struct Int3 { public int _1, _2, _3; }
[Benchmark] public Int3 ReturnInt3() => new Int3();
public struct Int4 { public int _1, _2, _3, _4; }
[Benchmark] public Int4 ReturnInt4() => new Int4();

[Benchmark] public long ReturnLong() => 0;
public struct Long1 { public long _1; }
[Benchmark] public Long1 ReturnLong1() => new Long1();
public struct Long2 { public long _1, _2; }
[Benchmark] public Long2 ReturnLong2() => new Long2();
public struct Long3 { public long _1, _2, _3; }
[Benchmark] public Long3 ReturnLong3() => new Long3();
public struct Long4 { public long _1, _2, _3, _4; }
[Benchmark] public Long4 ReturnLong4() => new Long4();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,40 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\BenchmarkDotNet.IntegrationTests\BenchmarkTestExecutor.cs" Link="BenchmarkTestExecutor.cs" />
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\MisconfiguredEnvironmentException.cs" Link="MisconfiguredEnvironmentException.cs" />
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\Extensions.cs" Link="Extensions.cs" />
<Compile Include="..\BenchmarkDotNet.IntegrationTests\TestConfigs.cs" Link="TestConfigs.cs" />
<Compile Include="..\BenchmarkDotNet.Tests\Loggers\OutputLogger.cs" Link="OutputLogger.cs" />
<Compile Include="..\BenchmarkDotNet.IntegrationTests\BenchmarkTestExecutor.cs">
<Link>Infra\BenchmarkTestExecutor.cs</Link>
</Compile>
<Compile Include="..\BenchmarkDotNet.IntegrationTests\TestConfigs.cs">
<Link>Infra\TestConfigs.cs</Link>
</Compile>
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\Extensions.cs">
<Link>Infra\Extensions.cs</Link>
</Compile>
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\MisconfiguredEnvironmentException.cs">
<Link>Infra\MisconfiguredEnvironmentException.cs</Link>
</Compile>
<Compile Include="..\BenchmarkDotNet.Tests\Loggers\OutputLogger.cs">
<Link>Infra\OutputLogger.cs</Link>
</Compile>
<Compile Include="..\BenchmarkDotNet.Tests\XUnit\*.cs" />
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\EnvRequirement.cs">
<Link>Infra\EnvRequirement.cs</Link>
</Compile>
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\EnvRequirementChecker.cs">
<Link>Infra\EnvRequirementChecker.cs</Link>
</Compile>
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\EnvRequirementCheckerTests.cs">
<Link>Infra\EnvRequirementCheckerTests.cs</Link>
</Compile>
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\FactEnvSpecific.cs">
<Link>Infra\FactEnvSpecific.cs</Link>
</Compile>
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\SmartAssert.cs">
<Link>Infra\SmartAssert.cs</Link>
</Compile>
<Compile Update="..\BenchmarkDotNet.Tests\XUnit\TheoryEnvSpecific.cs">
<Link>Infra\TheoryEnvSpecific.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="xunit.runner.json">
Expand Down
Loading

0 comments on commit fdf3b02

Please sign in to comment.