-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a7cc37
commit 35986fa
Showing
2 changed files
with
114 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Fastenshtein.Benchmarking | ||
{ | ||
[RankColumn] | ||
public abstract class ArrayBenchmark | ||
{ | ||
[Params(4, 25, 20_000)] | ||
public int N; | ||
|
||
protected int[] array; | ||
////protected nuint[] array2; | ||
|
||
[GlobalSetup] | ||
public void SetUp() | ||
{ | ||
this.array = new int[N]; | ||
////this.array2 = new nuint[N]; | ||
} | ||
////[Benchmark(Baseline = true)] | ||
////public int[] Simple() | ||
////{ | ||
//// for (int i = 0; i < array.Length; i++) | ||
//// { | ||
//// this.array[i] = i; | ||
//// } | ||
|
||
//// return this.array; | ||
////} | ||
|
||
[Benchmark(Baseline = true)] | ||
public int[] SimpleLocal() | ||
{ | ||
var tmp = this.array; | ||
|
||
for (int i = 0; i < tmp.Length; i++) | ||
{ | ||
tmp[i] = i; | ||
} | ||
|
||
return tmp; | ||
} | ||
|
||
//[Benchmark] | ||
//public nuint[] SimpleNuintLocal() | ||
//{ | ||
// var tmp = this.array2; | ||
// var len = (nuint) tmp.Length; | ||
|
||
// for (nuint i = 0; i < len; i++) | ||
// { | ||
// tmp[i] = i; | ||
// } | ||
|
||
// return tmp; | ||
//} | ||
|
||
[Benchmark] | ||
public int[] SimpleBackward() | ||
{ | ||
var tmp = this.array; | ||
|
||
for (int i = tmp.Length - 1; i >= 0; i--) | ||
{ | ||
tmp[i] = i; | ||
} | ||
|
||
return tmp; | ||
} | ||
|
||
[Benchmark] | ||
public int[] UnrollBackward() | ||
{ | ||
var tmp = this.array; | ||
int i = tmp.Length - 1; | ||
|
||
for (; i > 3; i -= 4) | ||
{ | ||
tmp[i] = i; | ||
tmp[i - 1] = i - 1; | ||
tmp[i - 2] = i - 2; | ||
tmp[i - 3] = i - 3; | ||
} | ||
|
||
for (; i >= 0; i--) | ||
{ | ||
tmp[i] = i; | ||
} | ||
|
||
return tmp; | ||
} | ||
} | ||
} |
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