Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions tests/src/JIT/Performance/CodeQuality/Span/SpanBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]

class Tests
namespace Span
{

public class SpanBench
{

#if DEBUG
const int Iterations = 1;
const int BubbleSortIterations = 1;
const int QuickSortIterations = 1;
const int FillAllIterations = 1;
#else
const int Iterations = 10000;
const int BubbleSortIterations = 1000;
const int QuickSortIterations = 10000;
const int FillAllIterations = 1000000;
#endif

const int Size = 1024;


[MethodImpl(MethodImplOptions.NoInlining)]
static void TestFillAllSpan(Span<byte> span)
{
Expand Down Expand Up @@ -198,7 +204,7 @@ public static void FillAllSpan()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllSpan(s);
}
Expand All @@ -214,7 +220,7 @@ public static void FillAllArray()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllArray(a);
}
Expand All @@ -231,7 +237,7 @@ public static void FillAllReverseSpan()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllReverseSpan(s);
}
Expand All @@ -247,7 +253,7 @@ public static void FillAllReverseArray()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllReverseArray(a);
}
Expand All @@ -266,7 +272,7 @@ public static void QuickSortSpan()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < QuickSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestQuickSortSpan(span);
Expand All @@ -286,7 +292,7 @@ public static void BubbleSortSpan()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < BubbleSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestBubbleSortSpan(span);
Expand All @@ -305,7 +311,7 @@ public static void QuickSortArray()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < QuickSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestQuickSortArray(data);
Expand All @@ -324,7 +330,7 @@ public static void BubbleSortArray()
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < BubbleSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestBubbleSortArray(data);
Expand All @@ -339,7 +345,7 @@ static void FillAllSpanBase()
{
byte[] a = new byte[Size];
Span<byte> s = new Span<byte>(a);
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllSpan(s);
}
Expand All @@ -348,7 +354,7 @@ static void FillAllSpanBase()
static void FillAllArrayBase()
{
byte[] a = new byte[Size];
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllArray(a);
}
Expand All @@ -358,7 +364,7 @@ static void FillAllReverseSpanBase()
{
byte[] a = new byte[Size];
Span<byte> s = new Span<byte>(a);
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllReverseSpan(s);
}
Expand All @@ -367,7 +373,7 @@ static void FillAllReverseSpanBase()
static void FillAllReverseArrayBase()
{
byte[] a = new byte[Size];
for (int i = 0; i < Iterations; i++)
for (int i = 0; i < FillAllIterations; i++)
{
TestFillAllReverseArray(a);
}
Expand All @@ -379,7 +385,7 @@ static void QuickSortSpanBase()
int[] unsortedData = GetUnsortedData();
Span<int> span = new Span<int>(data);

for (int i = 0; i < Iterations; i++)
for (int i = 0; i < QuickSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestQuickSortSpan(span);
Expand All @@ -392,7 +398,7 @@ static void BubbleSortSpanBase()
int[] unsortedData = GetUnsortedData();
Span<int> span = new Span<int>(data);

for (int i = 0; i < Iterations; i++)
for (int i = 0; i < BubbleSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestBubbleSortSpan(span);
Expand All @@ -404,7 +410,7 @@ static void QuickSortArrayBase()
int[] data = new int[Size];
int[] unsortedData = GetUnsortedData();

for (int i = 0; i < Iterations; i++)
for (int i = 0; i < QuickSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestQuickSortArray(data);
Expand All @@ -416,7 +422,7 @@ static void BubbleSortArrayBase()
int[] data = new int[Size];
int[] unsortedData = GetUnsortedData();

for (int i = 0; i < Iterations; i++)
for (int i = 0; i < BubbleSortIterations; i++)
{
Array.Copy(unsortedData, data, Size);
TestBubbleSortArray(data);
Expand Down Expand Up @@ -445,7 +451,7 @@ static IEnumerable<object[]> MakeArgs(params string[] args)

static Action LookupFunc(object o)
{
TypeInfo t = typeof(Tests).GetTypeInfo();
TypeInfo t = typeof(SpanBench).GetTypeInfo();
MethodInfo m = t.GetDeclaredMethod((string) o);
return m.CreateDelegate(typeof(Action)) as Action;
}
Expand All @@ -466,3 +472,4 @@ public static int Main(string[] args)
}
}

}