forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAccessing.cs
More file actions
51 lines (46 loc) · 1.31 KB
/
ArrayAccessing.cs
File metadata and controls
51 lines (46 loc) · 1.31 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
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
namespace NumSharp.Benchmark
{
//[RPlotExporter, RankColumn]
[SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
[SimpleJob(RunStrategy.Throughput, targetCount: 20)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[HtmlExporter]
public class ArrayAccessing
{
public double[] genericArray;
public Array nonGenericArray;
[GlobalSetup]
public void Setup()
{
var rnd = new Randomizer(42);
// first array
nonGenericArray = genericArray = new double[10_000_000];
for (int i = 0; i < genericArray.Length; i++)
{
genericArray[i] = rnd.NextDouble();
}
}
[Benchmark(Baseline = true)]
public void GenericAccess()
{
var length = genericArray.Length;
for (int i = 0; i < length; i++)
{
var a = genericArray[i];
}
}
[Benchmark]
public void NonGenericAccess()
{
double sum = 0;
var length = nonGenericArray.Length;
for (int i = 0; i < length; i++)
{
var a = nonGenericArray.GetValue(i);
}
}
}
}