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
71 lines (62 loc) · 1.9 KB
/
NDArrayTester1D.cs
File metadata and controls
71 lines (62 loc) · 1.9 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
using System;
using System.Numerics;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using NumSharp;
using NumSharp.Backends.Unmanaged;
namespace NumSharp.Benchmark
{
//[RPlotExporter, RankColumn]
[SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[HtmlExporter]
public class NDArrayTester1D
{
public NDArray np1;
public NDArray np2;
public NDArray np3;
public ArraySlice<double> np1Double;
public ArraySlice<double> np2Double;
public ArraySlice<double> np3Double;
[GlobalSetup]
public void Setup()
{
// first array
np1 = new NDArray(new double[100000].Select((x, idx) => x + idx).ToArray());
np1Double = np1.Data<double>();
// second array
np2 = new NDArray(new double[100000].Select((x, idx) => x + idx).ToArray());
np2Double = np2.Data<double>();
// result array
np3 = new NDArray(new double[100000]);
np3Double = np3.Data<double>();
// result array
np3 = new NDArray(new double[100000]);
np3Double = np3.Data<double>();
}
[Benchmark]
public void DirectAddition1D()
{
for (int idx = 0; idx < np3Double.Count; idx++)
np3Double[idx] = np1Double[idx] + np2Double[idx];
}
[Benchmark]
public void NDArrayAddition1D()
{
np3 = np1 + np2;
}
[Benchmark]
public void DirectSubstration1D()
{
for (int idx = 0; idx < np3Double.Count; idx++)
np3Double[idx] = np1Double[idx] - np2Double[idx];
}
[Benchmark]
public void NDArraySubstraction1D()
{
np3 = np1 - np2;
}
}
}