-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding array PopulateCosts into base for benchmarking
- Loading branch information
1 parent
334c1af
commit b5cca54
Showing
7 changed files
with
99 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#if NET8_0_OR_GREATER | ||
using System.Numerics; | ||
#endif | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Fastenshtein | ||
{ | ||
internal static class ArrayFill | ||
{ | ||
#if NET8_0_OR_GREATER | ||
private static readonly int[] indexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
private static readonly Vector<int> additionVector = new(Vector<int>.Count); | ||
private static readonly Vector<int> indexesVector = new(indexes); | ||
#endif | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static void PopulateCosts(int[] costs) | ||
{ | ||
int i = 0; | ||
#if NET8_0_OR_GREATER | ||
if (Vector.IsHardwareAccelerated) | ||
{ | ||
int lastBlockIndex = costs.Length - (costs.Length % Vector<int>.Count); | ||
|
||
var previous = indexesVector; | ||
|
||
while (i < lastBlockIndex) | ||
{ | ||
previous.StoreUnsafe(ref costs[i]); | ||
previous += additionVector; | ||
i += Vector<int>.Count; | ||
} | ||
} | ||
#endif | ||
for (; i < costs.Length; i++) | ||
{ | ||
costs[i] = i; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
namespace Fastenshtein.Tests | ||
{ | ||
using Fastenshtein.Benchmarking; | ||
using System.Linq; | ||
using Xunit; | ||
////namespace Fastenshtein.Tests | ||
////{ | ||
//// using Fastenshtein.Benchmarking; | ||
//// using System.Linq; | ||
//// using Xunit; | ||
|
||
public class ArrayFillTests | ||
{ | ||
[Theory] | ||
[InlineData(0)] | ||
[InlineData(1)] | ||
[InlineData(4)] | ||
[InlineData(8)] | ||
[InlineData(9)] | ||
[InlineData(1024)] | ||
public void Repeated_Distance_Calls_Return_Correct_Distances(int length) | ||
{ | ||
var onTest = new ArrayBenchmark(); | ||
onTest.N = length; | ||
//// public class ArrayFillTests | ||
//// { | ||
//// [Theory] | ||
//// [InlineData(0)] | ||
//// [InlineData(1)] | ||
//// [InlineData(4)] | ||
//// [InlineData(8)] | ||
//// [InlineData(9)] | ||
//// [InlineData(1024)] | ||
//// public void Repeated_Distance_Calls_Return_Correct_Distances(int length) | ||
//// { | ||
//// var onTest = new ArrayBenchmark(); | ||
//// onTest.N = length; | ||
|
||
var methods = onTest | ||
.GetType() | ||
.GetMethods() | ||
.Where(x => x.ReturnType == typeof(int[])); | ||
//// var methods = onTest | ||
//// .GetType() | ||
//// .GetMethods() | ||
//// .Where(x => x.ReturnType == typeof(int[])); | ||
|
||
foreach (var method in methods) | ||
{ | ||
onTest.SetUp(); | ||
//// foreach (var method in methods) | ||
//// { | ||
//// onTest.SetUp(); | ||
|
||
var array = (int[])method.Invoke(onTest, null); | ||
//// var array = (int[])method.Invoke(onTest, null); | ||
|
||
for (var i = 0; i < array.Length; i++) | ||
{ | ||
Assert.Equal(i, array[i]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
//// for (var i = 0; i < array.Length; i++) | ||
//// { | ||
//// Assert.Equal(i, array[i]); | ||
//// } | ||
//// } | ||
//// } | ||
//// } | ||
////} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters