Skip to content

Commit

Permalink
Move Smoke benchmarks to BenchmarkDotNet.Samples
Browse files Browse the repository at this point in the history
IntroSmokeIncrements was taken from #2334 (comment)
  • Loading branch information
AndreyAkinshin committed Aug 28, 2024
1 parent 92f33f2 commit 475ab45
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 159 deletions.
82 changes: 82 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeEmptyBasic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples;

[DisassemblyDiagnoser]
public class IntroSmokeEmptyBasic
{
[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;
}
138 changes: 138 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeIncrements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using BenchmarkDotNet.Attributes;

namespace BenchmarkDotNet.Samples;

public class IntroSmokeIncrements
{
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++;
}
}
70 changes: 70 additions & 0 deletions samples/BenchmarkDotNet.Samples/IntroSmokeValueTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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();
}
// ReSharper restore InconsistentNaming

This file was deleted.

Loading

0 comments on commit 475ab45

Please sign in to comment.