|
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; |
7 | 7 |
|
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 | |
25 | 25 |
|
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; |
34 | 34 |
|
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; |
39 | 39 |
|
40 | | - private UnmanagedMemoryBlock<int> fromsimple; |
41 | | - private UnmanagedMemoryBlock<int> tosimple; |
| 40 | +// private UnmanagedMemoryBlock<int> fromsimple; |
| 41 | +// private UnmanagedMemoryBlock<int> tosimple; |
42 | 42 |
|
43 | | - NDArray nd; |
| 43 | +// NDArray nd; |
44 | 44 |
|
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); |
53 | 53 |
|
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 | +// } |
57 | 57 |
|
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 | +// } |
71 | 71 |
|
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 | +// } |
80 | 80 |
|
81 | | - UnmanagedByteStorage<int>[] memoryTrash; |
| 81 | +// //UnmanagedByteStorage<int>[] memoryTrash; |
82 | 82 |
|
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 | +// //} |
92 | 92 |
|
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 | +// } |
101 | 101 |
|
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 | +// } |
112 | 112 |
|
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 | +// } |
126 | 126 |
|
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