Skip to content

Commit

Permalink
Add bechmarks for short and Half where supported
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Jan 21, 2024
1 parent e7ec730 commit 29e5c97
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/NetFabric.Numerics.Tensors.Benchmarks/Sum2DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Sum2DBenchmarks
MyVector2<float>[]? arrayFloat;
MyVector2<double>[]? arrayDouble;

[Params(10_000)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -45,6 +45,11 @@ public void GlobalSetup()
public MyVector2<short> Baseline_Short()
=> Baseline.Sum<MyVector2<short>>(arrayShort!);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector2<short> LINQ_Short()
=> Enumerable.Aggregate(arrayShort!, MyVector2<short>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector2<short> Tensor_Short()
Expand Down Expand Up @@ -94,6 +99,11 @@ public MyVector2<long> Tensor_Long()
public MyVector2<Half> Baseline_Half()
=> Baseline.Sum<MyVector2<Half>>(arrayHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector2<Half> LINQ_Half()
=> Enumerable.Aggregate(arrayHalf!, MyVector2<Half>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector2<Half> Tensor_Half()
Expand Down
12 changes: 11 additions & 1 deletion src/NetFabric.Numerics.Tensors.Benchmarks/Sum3DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Sum3DBenchmarks
MyVector3<float>[]? arrayFloat;
MyVector3<double>[]? arrayDouble;

[Params(10_000)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -45,6 +45,11 @@ public void GlobalSetup()
public MyVector3<short> Baseline_Short()
=> Baseline.Sum<MyVector3<short>>(arrayShort!);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector3<short> LINQ_Short()
=> Enumerable.Aggregate(arrayShort!, MyVector3<short>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector3<short> Tensor_Short()
Expand Down Expand Up @@ -94,6 +99,11 @@ public MyVector3<long> Tensor_Long()
public MyVector3<Half> Baseline_Half()
=> Baseline.Sum<MyVector3<Half>>(arrayHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector3<Half> LINQ_Half()
=> Enumerable.Aggregate(arrayHalf!, MyVector3<Half>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector3<Half> Tensor_Half()
Expand Down
12 changes: 11 additions & 1 deletion src/NetFabric.Numerics.Tensors.Benchmarks/Sum4DBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Sum4DBenchmarks
MyVector4<float>[]? arrayFloat;
MyVector4<double>[]? arrayDouble;

[Params(10_000)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -45,6 +45,11 @@ public void GlobalSetup()
public MyVector4<short> Baseline_Short()
=> Baseline.Sum<MyVector4<short>>(arrayShort!);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector4<short> LINQ_Short()
=> Enumerable.Aggregate(arrayShort!, MyVector4<short>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Short")]
[Benchmark]
public MyVector4<short> Tensor_Short()
Expand Down Expand Up @@ -94,6 +99,11 @@ public MyVector4<long> Tensor_Long()
public MyVector4<Half> Baseline_Half()
=> Baseline.Sum<MyVector4<Half>>(arrayHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector4<Half> LINQ_Half()
=> Enumerable.Aggregate(arrayHalf!, MyVector4<Half>.AdditiveIdentity, (sum, item) => sum + item);

[BenchmarkCategory("Half")]
[Benchmark]
public MyVector4<Half> Tensor_Half()
Expand Down
12 changes: 11 additions & 1 deletion src/NetFabric.Numerics.Tensors.Benchmarks/SumBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SumBenchmarks
float[]? arrayFloat;
double[]? arrayDouble;

[Params(10_000)]
[Params(1_000)]
public int Count { get; set; }

[GlobalSetup]
Expand Down Expand Up @@ -46,6 +46,11 @@ public void GlobalSetup()
public short Baseline_Short()
=> Baseline.Sum<short>(arrayShort!);

[BenchmarkCategory("Short")]
[Benchmark]
public short LINQ_Short()
=> Enumerable.Aggregate(arrayShort!, (short)0, (sum, item) => (short)(sum + item));

[BenchmarkCategory("Short")]
[Benchmark]
public short Tensor_Short()
Expand Down Expand Up @@ -86,6 +91,11 @@ public long Tensor_Long()
public Half Baseline_Half()
=> Baseline.Sum<Half>(arrayHalf!);

[BenchmarkCategory("Half")]
[Benchmark]
public Half LINQ_Half()
=> Enumerable.Aggregate(arrayHalf!, (Half)0, (sum, item) => (Half)(sum + item));

[BenchmarkCategory("Half")]
[Benchmark]
public Half Tensor_Half()
Expand Down

0 comments on commit 29e5c97

Please sign in to comment.