forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDArrayTester1D.cs
More file actions
76 lines (67 loc) · 2.07 KB
/
NDArrayTester1D.cs
File metadata and controls
76 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Numerics;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using NumSharp.Core;
namespace NumSharp.Benchmark
{
//[RPlotExporter, RankColumn]
[SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[HtmlExporter]
public class NDArrayTester1D
{
public NDArray<double> np1;
public NDArray<double> np2;
public NDArray<double> np3;
public double[] np1Double;
public double[] np2Double;
public double[] np3Double;
[GlobalSetup]
public void Setup()
{
// first array
np1 = new NDArray<double>();
np1.Data = new double[100000].Select((x,idx) => x + idx ).ToArray();
np1.Shape = new Shape(np1.Data.Length);
np1Double = np1.Data;
// second array
np2 = new NDArray<double>();
np2.Data = new double[100000].Select((x,idx) => x + idx ).ToArray();
np2.Shape = new Shape(np2.Data.Length);
np2Double = np2.Data;
// result array
np3 = new NDArray<double>();
np3.Data = new double[100000];
np3Double = np3.Data;
// result array
np3 = new NDArray<double>();
np3.Data = new double[100000];
np3Double = np3.Data;
}
[Benchmark]
public void DirectAddition1D()
{
for(int idx = 0; idx < np3Double.Length;idx++)
np3Double[idx] = np1Double[idx] + np2Double[idx];
}
[Benchmark]
public void NDArrayAddition1D()
{
np3 = np1 + np2;
}
[Benchmark]
public void DirectSubstration1D()
{
for(int idx = 0; idx < np3Double.Length;idx++)
np3Double[idx] = np1Double[idx] - np2Double[idx];
}
[Benchmark]
public void NDArraySubstraction1D()
{
np3 = np1 - np2;
}
}
}