Repository navigation
Expand file tree
/
Copy pathArrayAssignmentUnspecifiedType.cs
More file actions
80 lines (71 loc) · 2.17 KB
/
Copy pathArrayAssignmentUnspecifiedType.cs
File metadata and controls
80 lines (71 loc) · 2.17 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
77
78
79
80
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using NumSharp.Backends;
using NumSharp.Utilities;
namespace NumSharp.Benchmark
{
[SimpleJob(RunStrategy.ColdStart, iterationCount: 3)]
[SimpleJob(RunStrategy.Throughput, iterationCount: 3)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[HtmlExporter]
public class ArrayAssignmentUnspecifiedType
{
public object[] randomCoinedDouble;
public object[] allFalseArray;
protected Boolean[] _arrayBoolean;
[GlobalSetup]
public void Setup()
{
var rnd = new MT19937(42);
// first array
randomCoinedDouble = new object[10000];
for (int i = 0; i < randomCoinedDouble.Length; i++)
{
randomCoinedDouble[i] = rnd.NextDouble() > 0.5d ? 1d : 0d;
}
_arrayBoolean = new bool[10000];
allFalseArray = new object[10000];
for (int i = 0; i < allFalseArray.Length; i++)
{
allFalseArray[i] = false;
}
}
[Benchmark(Baseline = true)]
public void Convert()
{
for (int i = 0; i < 10000; i++)
{
var val = allFalseArray[i];
_arrayBoolean[i] = System.Convert.ToBoolean(val);
}
}
[Benchmark]
public void AsConvert()
{
for (int i = 0; i < 10000; i++)
{
var val = allFalseArray[i];
_arrayBoolean[i] = val as Boolean? ?? System.Convert.ToBoolean(val);
}
}
[Benchmark]
public void ConvertRandomValue()
{
for (int i = 0; i < 10000; i++)
{
var val = randomCoinedDouble[i];
_arrayBoolean[i] = System.Convert.ToBoolean(val);
}
}
[Benchmark]
public void AsConvertRandomValue()
{
for (int i = 0; i < 10000; i++)
{
var val = randomCoinedDouble[i];
_arrayBoolean[i] = val as Boolean? ?? System.Convert.ToBoolean(val);
}
}
}
}