Skip to content

Commit 897bbc7

Browse files
committed
Fixed compilation for unit tests and benchmark proj.
1 parent f222f70 commit 897bbc7

9 files changed

Lines changed: 804 additions & 1035 deletions

File tree

test/NumSharp.Benchmark/Unmanaged/GetSpanLargeLength.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public unsafe class GetSpanLargeLength
3333
private const int iterations = 100;
3434

3535
private UnmanagedMemoryBlock<int> from;
36-
private UnmanagedByteStorage<int> fromvec;
36+
//private UnmanagedByteStorage<int> fromvec;
3737
private UnmanagedMemoryBlock<int> to;
38-
private UnmanagedByteStorage<int> setvec;
38+
//private UnmanagedByteStorage<int> setvec;
3939

4040
private UnmanagedMemoryBlock<int> fromsimple;
4141
private UnmanagedMemoryBlock<int> tosimple;
@@ -46,9 +46,9 @@ public unsafe class GetSpanLargeLength
4646
public void Setup()
4747
{
4848
@from = new UnmanagedMemoryBlock<int>(length);
49-
fromvec = new UnmanagedByteStorage<int>(new int[10 * length], new Shape(10, length));
49+
//fromvec = new UnmanagedByteStorage<int>(new int[10 * length], new Shape(10, length));
5050
to = new UnmanagedMemoryBlock<int>(length);
51-
setvec = new UnmanagedByteStorage<int>(Enumerable.Range(0, length).ToArray(), new Shape(length));
51+
//setvec = new UnmanagedByteStorage<int>(Enumerable.Range(0, length).ToArray(), new Shape(length));
5252
nd = np.arange(length * 10).reshape(10, length);
5353

5454
fromsimple = new UnmanagedMemoryBlock<int>(length);
@@ -68,27 +68,27 @@ public void Cleanup()
6868
// }
6969
}
7070

71-
[Benchmark]
72-
public void VectorNonCopy()
73-
{
74-
for (int j = 0; j < iterations; j++)
75-
{
76-
var _ = fromvec.Get(3);
77-
}
78-
}
71+
//[Benchmark]
72+
//public void VectorNonCopy()
73+
//{
74+
// for (int j = 0; j < iterations; j++)
75+
// {
76+
// var _ = fromvec.Get(3);
77+
// }
78+
//}
7979

80-
UnmanagedByteStorage<int>[] memoryTrash;
80+
//UnmanagedByteStorage<int>[] memoryTrash;
8181

82-
[Benchmark]
83-
public void VectorWithCopy()
84-
{
85-
memoryTrash = new UnmanagedByteStorage<int>[iterations];
86-
for (int j = 0; j < iterations; j++)
87-
{
88-
//memoryTrash[j] = fromvec.Get(3).Clone();
89-
fromvec.GetCopy(3).Clone();
90-
}
91-
}
82+
//[Benchmark]
83+
//public void VectorWithCopy()
84+
//{
85+
// memoryTrash = new UnmanagedByteStorage<int>[iterations];
86+
// for (int j = 0; j < iterations; j++)
87+
// {
88+
// //memoryTrash[j] = fromvec.Get(3).Clone();
89+
// fromvec.GetCopy(3).Clone();
90+
// }
91+
//}
9292

9393
[Benchmark]
9494
public void NDArray()
Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,140 @@
1-
using System;
2-
using System.Linq;
3-
using System.Runtime.CompilerServices;
4-
using BenchmarkDotNet.Attributes;
5-
using BenchmarkDotNet.Engines;
6-
using NumSharp.Backends.Unmanaged;
1+
//using System;
2+
//using System.Linq;
3+
//using System.Runtime.CompilerServices;
4+
//using BenchmarkDotNet.Attributes;
5+
//using BenchmarkDotNet.Engines;
6+
//using NumSharp.Backends.Unmanaged;
77

8-
namespace NumSharp.Benchmark.Unmanaged
9-
{
10-
//| Method | RunStrategy | Mean | Error | StdDev | Median | Min | Max | Ratio | RatioSD |
11-
//|--------------- |------------ |-------------:|---------------:|---------------:|-------------:|------------:|-------------:|-------:|--------:|
12-
//| VectorNonCopy | ColdStart | 1,355.8 us | 774.3699 us | 891.7655 us | 1,134.7 us | 1,071.9 us | 5,124.9 us | 8.26 | 1.12 |
13-
//| VectorWithCopy | ColdStart | 116,122.1 us | 44,224.4978 us | 50,928.9974 us | 99,734.1 us | 93,455.4 us | 327,380.6 us | 812.20 | 411.45 |
14-
//| NDArray | ColdStart | 9,481.6 us | 1,878.5694 us | 2,163.3633 us | 8,922.2 us | 8,176.8 us | 17,232.6 us | 63.68 | 14.33 |
15-
//| SimpleArray | ColdStart | 185.2 us | 186.2988 us | 214.5420 us | 136.0 us | 135.5 us | 1,096.4 us | 1.00 | 0.00 |
16-
//| ManualCopy | ColdStart | 1,158.0 us | 194.1728 us | 223.6097 us | 1,103.5 us | 1,099.4 us | 2,107.2 us | 7.78 | 1.41 |
17-
//| MemoryCopy | ColdStart | 189.5 us | 219.4025 us | 252.6643 us | 130.4 us | 130.2 us | 1,262.5 us | 0.98 | 0.07 |
18-
//| | | | | | | | | | |
19-
//| VectorNonCopy | Throughput | 1,174.8 us | 39.6416 us | 42.4160 us | 1,161.7 us | 1,117.3 us | 1,294.7 us | 8.69 | 0.32 |
20-
//| VectorWithCopy | Throughput | 107,212.1 us | 12,329.5115 us | 13,704.2193 us | 102,322.9 us | 95,017.6 us | 138,940.6 us | 798.46 | 104.51 |
21-
//| NDArray | Throughput | 8,386.5 us | 139.0418 us | 154.5446 us | 8,415.6 us | 8,142.1 us | 8,641.9 us | 61.92 | 1.21 |
22-
//| SimpleArray | Throughput | 135.4 us | 0.3412 us | 0.3504 us | 135.3 us | 135.2 us | 136.0 us | 1.00 | 0.00 |
23-
//| ManualCopy | Throughput | 1,106.2 us | 9.3761 us | 10.4215 us | 1,102.8 us | 1,097.2 us | 1,127.6 us | 8.17 | 0.07 |
24-
//| MemoryCopy | Throughput | 132.9 us | 3.1830 us | 3.5379 us | 130.8 us | 130.1 us | 140.3 us | 0.98 | 0.03 |
8+
//namespace NumSharp.Benchmark.Unmanaged
9+
//{
10+
// //| Method | RunStrategy | Mean | Error | StdDev | Median | Min | Max | Ratio | RatioSD |
11+
// //|--------------- |------------ |-------------:|---------------:|---------------:|-------------:|------------:|-------------:|-------:|--------:|
12+
// //| VectorNonCopy | ColdStart | 1,355.8 us | 774.3699 us | 891.7655 us | 1,134.7 us | 1,071.9 us | 5,124.9 us | 8.26 | 1.12 |
13+
// //| VectorWithCopy | ColdStart | 116,122.1 us | 44,224.4978 us | 50,928.9974 us | 99,734.1 us | 93,455.4 us | 327,380.6 us | 812.20 | 411.45 |
14+
// //| NDArray | ColdStart | 9,481.6 us | 1,878.5694 us | 2,163.3633 us | 8,922.2 us | 8,176.8 us | 17,232.6 us | 63.68 | 14.33 |
15+
// //| SimpleArray | ColdStart | 185.2 us | 186.2988 us | 214.5420 us | 136.0 us | 135.5 us | 1,096.4 us | 1.00 | 0.00 |
16+
// //| ManualCopy | ColdStart | 1,158.0 us | 194.1728 us | 223.6097 us | 1,103.5 us | 1,099.4 us | 2,107.2 us | 7.78 | 1.41 |
17+
// //| MemoryCopy | ColdStart | 189.5 us | 219.4025 us | 252.6643 us | 130.4 us | 130.2 us | 1,262.5 us | 0.98 | 0.07 |
18+
// //| | | | | | | | | | |
19+
// //| VectorNonCopy | Throughput | 1,174.8 us | 39.6416 us | 42.4160 us | 1,161.7 us | 1,117.3 us | 1,294.7 us | 8.69 | 0.32 |
20+
// //| VectorWithCopy | Throughput | 107,212.1 us | 12,329.5115 us | 13,704.2193 us | 102,322.9 us | 95,017.6 us | 138,940.6 us | 798.46 | 104.51 |
21+
// //| NDArray | Throughput | 8,386.5 us | 139.0418 us | 154.5446 us | 8,415.6 us | 8,142.1 us | 8,641.9 us | 61.92 | 1.21 |
22+
// //| SimpleArray | Throughput | 135.4 us | 0.3412 us | 0.3504 us | 135.3 us | 135.2 us | 136.0 us | 1.00 | 0.00 |
23+
// //| ManualCopy | Throughput | 1,106.2 us | 9.3761 us | 10.4215 us | 1,102.8 us | 1,097.2 us | 1,127.6 us | 8.17 | 0.07 |
24+
// //| MemoryCopy | Throughput | 132.9 us | 3.1830 us | 3.5379 us | 130.8 us | 130.1 us | 140.3 us | 0.98 | 0.03 |
2525

26-
[SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
27-
[SimpleJob(RunStrategy.Throughput, targetCount: 20)]
28-
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
29-
[HtmlExporter]
30-
public unsafe class GetSpanSmallLength
31-
{
32-
private const int length = 100;
33-
private const int iterations = 20_000;
26+
// [SimpleJob(RunStrategy.ColdStart, targetCount: 20)]
27+
// [SimpleJob(RunStrategy.Throughput, targetCount: 20)]
28+
// [MinColumn, MaxColumn, MeanColumn, MedianColumn]
29+
// [HtmlExporter]
30+
// public unsafe class GetSpanSmallLength
31+
// {
32+
// private const int length = 100;
33+
// private const int iterations = 20_000;
3434

35-
private UnmanagedMemoryBlock<int> from;
36-
private UnmanagedByteStorage<int> fromvec;
37-
private UnmanagedMemoryBlock<int> to;
38-
private UnmanagedByteStorage<int> setvec;
35+
// private UnmanagedMemoryBlock<int> from;
36+
// private UnmanagedByteStorage<int> fromvec;
37+
// private UnmanagedMemoryBlock<int> to;
38+
// private UnmanagedByteStorage<int> setvec;
3939

40-
private UnmanagedMemoryBlock<int> fromsimple;
41-
private UnmanagedMemoryBlock<int> tosimple;
40+
// private UnmanagedMemoryBlock<int> fromsimple;
41+
// private UnmanagedMemoryBlock<int> tosimple;
4242

43-
NDArray nd;
43+
// NDArray nd;
4444

45-
[GlobalSetup]
46-
public void Setup()
47-
{
48-
@from = new UnmanagedMemoryBlock<int>(length);
49-
fromvec = new UnmanagedByteStorage<int>(new int[10 * length], new Shape(10, length));
50-
to = new UnmanagedMemoryBlock<int>(length);
51-
setvec = new UnmanagedByteStorage<int>(Enumerable.Range(0, length).ToArray(), new Shape(length));
52-
nd = np.arange(length * 10).reshape(10, length);
45+
// [GlobalSetup]
46+
// public void Setup()
47+
// {
48+
// @from = new UnmanagedMemoryBlock<int>(length);
49+
// fromvec = new UnmanagedByteStorage<int>(new int[10 * length], new Shape(10, length));
50+
// to = new UnmanagedMemoryBlock<int>(length);
51+
// setvec = new UnmanagedByteStorage<int>(Enumerable.Range(0, length).ToArray(), new Shape(length));
52+
// nd = np.arange(length * 10).reshape(10, length);
5353

54-
fromsimple = new UnmanagedMemoryBlock<int>(length);
55-
tosimple = new UnmanagedMemoryBlock<int>(length);
56-
}
54+
// fromsimple = new UnmanagedMemoryBlock<int>(length);
55+
// tosimple = new UnmanagedMemoryBlock<int>(length);
56+
// }
5757

58-
[BenchmarkDotNet.Attributes.IterationCleanup()]
59-
public void Cleanup()
60-
{
61-
if (memoryTrash != null)
62-
for (var i = 0; i < memoryTrash.Length; i++)
63-
{
64-
var vector = memoryTrash[i];
65-
if (vector == null)
66-
break;
67-
vector.Free();
68-
memoryTrash[i] = null;
69-
}
70-
}
58+
// [BenchmarkDotNet.Attributes.IterationCleanup()]
59+
// public void Cleanup()
60+
// {
61+
// if (memoryTrash != null)
62+
// for (var i = 0; i < memoryTrash.Length; i++)
63+
// {
64+
// var vector = memoryTrash[i];
65+
// if (vector == null)
66+
// break;
67+
// vector.Free();
68+
// memoryTrash[i] = null;
69+
// }
70+
// }
7171

72-
[Benchmark]
73-
public void VectorNonCopy()
74-
{
75-
for (int j = 0; j < iterations; j++)
76-
{
77-
var _ = fromvec.Get(3);
78-
}
79-
}
72+
// [Benchmark]
73+
// public void VectorNonCopy()
74+
// {
75+
// for (int j = 0; j < iterations; j++)
76+
// {
77+
// var _ = fromvec.Get(3);
78+
// }
79+
// }
8080

81-
UnmanagedByteStorage<int>[] memoryTrash;
81+
// //UnmanagedByteStorage<int>[] memoryTrash;
8282

83-
[Benchmark]
84-
public void VectorWithCopy()
85-
{
86-
memoryTrash = new UnmanagedByteStorage<int>[iterations];
87-
for (int j = 0; j < iterations; j++)
88-
{
89-
var _ = fromvec.GetCopy(3);
90-
}
91-
}
83+
// //[Benchmark]
84+
// //public void VectorWithCopy()
85+
// //{
86+
// // memoryTrash = new UnmanagedByteStorage<int>[iterations];
87+
// // for (int j = 0; j < iterations; j++)
88+
// // {
89+
// // var _ = fromvec.GetCopy(3);
90+
// // }
91+
// //}
9292

93-
[Benchmark]
94-
public void NDArray()
95-
{
96-
for (int j = 0; j < iterations; j++)
97-
{
98-
var _ = nd[3];
99-
}
100-
}
93+
// [Benchmark]
94+
// public void NDArray()
95+
// {
96+
// for (int j = 0; j < iterations; j++)
97+
// {
98+
// var _ = nd[3];
99+
// }
100+
// }
101101

102-
[Benchmark(Baseline = true)]
103-
public void SimpleArray()
104-
{
105-
var fromspan = fromsimple.AsSpan();
106-
var tospan = tosimple.AsSpan();
107-
for (int i = 0; i < iterations; i++)
108-
{
109-
fromspan.CopyTo(tospan);
110-
}
111-
}
102+
// [Benchmark(Baseline = true)]
103+
// public void SimpleArray()
104+
// {
105+
// var fromspan = fromsimple.AsSpan();
106+
// var tospan = tosimple.AsSpan();
107+
// for (int i = 0; i < iterations; i++)
108+
// {
109+
// fromspan.CopyTo(tospan);
110+
// }
111+
// }
112112

113-
[Benchmark]
114-
public void ManualCopy()
115-
{
116-
int* frm = (int*)Unsafe.AsPointer(ref fromsimple.GetPinnableReference());
117-
int* to = (int*)Unsafe.AsPointer(ref tosimple.GetPinnableReference());
118-
for (int j = 0; j < iterations; j++)
119-
{
120-
for (int i = 0; i < length; i++)
121-
{
122-
*(to + i) = *(frm + i);
123-
}
124-
}
125-
}
113+
// [Benchmark]
114+
// public void ManualCopy()
115+
// {
116+
// int* frm = (int*)Unsafe.AsPointer(ref fromsimple.GetPinnableReference());
117+
// int* to = (int*)Unsafe.AsPointer(ref tosimple.GetPinnableReference());
118+
// for (int j = 0; j < iterations; j++)
119+
// {
120+
// for (int i = 0; i < length; i++)
121+
// {
122+
// *(to + i) = *(frm + i);
123+
// }
124+
// }
125+
// }
126126

127-
[Benchmark]
128-
public void MemoryCopy()
129-
{
130-
int* frm = (int*)Unsafe.AsPointer(ref fromsimple.GetPinnableReference());
131-
int* to = (int*)Unsafe.AsPointer(ref tosimple.GetPinnableReference());
132-
var single = sizeof(int);
133-
var len = length * single;
134-
for (int j = 0; j < iterations; j++)
135-
{
136-
Buffer.MemoryCopy(frm, to, len, len);
137-
}
138-
}
139-
}
140-
}
127+
// [Benchmark]
128+
// public void MemoryCopy()
129+
// {
130+
// int* frm = (int*)Unsafe.AsPointer(ref fromsimple.GetPinnableReference());
131+
// int* to = (int*)Unsafe.AsPointer(ref tosimple.GetPinnableReference());
132+
// var single = sizeof(int);
133+
// var len = length * single;
134+
// for (int j = 0; j < iterations; j++)
135+
// {
136+
// Buffer.MemoryCopy(frm, to, len, len);
137+
// }
138+
// }
139+
// }
140+
//}

0 commit comments

Comments
 (0)