|
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 | Toolchain | IterationCount | RunStrategy | UnrollFactor | Mean | Error | StdDev | Min | Max | Median | Ratio | RatioSD | |
11 |
| - //|--------------- |------------------- |--------------- |------------ |------------- |-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-------:|--------:| |
12 |
| - //| VectorNonCopy | Default | 20 | ColdStart | 1 | 9.535 ms | 1.1402 ms | 1.3130 ms | 8.724 ms | 13.096 ms | 8.995 ms | 6.23 | 0.99 | |
13 |
| - //| VectorWithCopy | Default | 20 | ColdStart | 1 | 351.689 ms | 11.8808 ms | 13.6819 ms | 330.815 ms | 376.969 ms | 352.871 ms | 231.10 | 30.29 | |
14 |
| - //| NDArray | Default | 20 | ColdStart | 1 | 78.610 ms | 3.0417 ms | 3.5028 ms | 75.879 ms | 88.297 ms | 77.575 ms | 51.58 | 6.39 | |
15 |
| - //| SimpleArray | Default | 20 | ColdStart | 1 | 1.551 ms | 0.2153 ms | 0.2480 ms | 1.411 ms | 2.243 ms | 1.439 ms | 1.00 | 0.00 | |
16 |
| - //| ManualCopy | Default | 20 | ColdStart | 1 | 7.641 ms | 0.1747 ms | 0.2012 ms | 7.538 ms | 8.430 ms | 7.580 ms | 5.01 | 0.57 | |
17 |
| - //| MemoryCopy | Default | 20 | ColdStart | 1 | 1.394 ms | 0.1777 ms | 0.2047 ms | 1.302 ms | 2.173 ms | 1.329 ms | 0.91 | 0.11 | |
18 |
| - //| | | | | | | | | | | | | | |
19 |
| - //| VectorNonCopy | Default | 20 | Throughput | 16 | 9.159 ms | 0.1123 ms | 0.1293 ms | 8.992 ms | 9.457 ms | 9.139 ms | 6.71 | 0.10 | |
20 |
| - //| VectorWithCopy | Default | 20 | Throughput | 16 | 356.050 ms | 12.3996 ms | 13.2675 ms | 336.000 ms | 381.900 ms | 356.417 ms | 260.50 | 10.13 | |
21 |
| - //| NDArray | Default | 20 | Throughput | 16 | 73.999 ms | 1.7034 ms | 1.8227 ms | 71.696 ms | 77.212 ms | 73.811 ms | 54.14 | 1.40 | |
22 |
| - //| SimpleArray | Default | 20 | Throughput | 16 | 1.366 ms | 0.0074 ms | 0.0082 ms | 1.356 ms | 1.385 ms | 1.366 ms | 1.00 | 0.00 | |
23 |
| - //| ManualCopy | Default | 20 | Throughput | 16 | 7.345 ms | 0.0397 ms | 0.0408 ms | 7.286 ms | 7.423 ms | 7.348 ms | 5.37 | 0.04 | |
24 |
| - //| MemoryCopy | Default | 20 | Throughput | 16 | 1.348 ms | 0.0261 ms | 0.0268 ms | 1.323 ms | 1.416 ms | 1.343 ms | 0.99 | 0.02 | |
| 8 | +//namespace NumSharp.Benchmark.Unmanaged |
| 9 | +//{ |
| 10 | +// //| Method | Toolchain | IterationCount | RunStrategy | UnrollFactor | Mean | Error | StdDev | Min | Max | Median | Ratio | RatioSD | |
| 11 | +// //|--------------- |------------------- |--------------- |------------ |------------- |-----------:|-----------:|-----------:|-----------:|-----------:|-----------:|-------:|--------:| |
| 12 | +// //| VectorNonCopy | Default | 20 | ColdStart | 1 | 9.535 ms | 1.1402 ms | 1.3130 ms | 8.724 ms | 13.096 ms | 8.995 ms | 6.23 | 0.99 | |
| 13 | +// //| VectorWithCopy | Default | 20 | ColdStart | 1 | 351.689 ms | 11.8808 ms | 13.6819 ms | 330.815 ms | 376.969 ms | 352.871 ms | 231.10 | 30.29 | |
| 14 | +// //| NDArray | Default | 20 | ColdStart | 1 | 78.610 ms | 3.0417 ms | 3.5028 ms | 75.879 ms | 88.297 ms | 77.575 ms | 51.58 | 6.39 | |
| 15 | +// //| SimpleArray | Default | 20 | ColdStart | 1 | 1.551 ms | 0.2153 ms | 0.2480 ms | 1.411 ms | 2.243 ms | 1.439 ms | 1.00 | 0.00 | |
| 16 | +// //| ManualCopy | Default | 20 | ColdStart | 1 | 7.641 ms | 0.1747 ms | 0.2012 ms | 7.538 ms | 8.430 ms | 7.580 ms | 5.01 | 0.57 | |
| 17 | +// //| MemoryCopy | Default | 20 | ColdStart | 1 | 1.394 ms | 0.1777 ms | 0.2047 ms | 1.302 ms | 2.173 ms | 1.329 ms | 0.91 | 0.11 | |
| 18 | +// //| | | | | | | | | | | | | | |
| 19 | +// //| VectorNonCopy | Default | 20 | Throughput | 16 | 9.159 ms | 0.1123 ms | 0.1293 ms | 8.992 ms | 9.457 ms | 9.139 ms | 6.71 | 0.10 | |
| 20 | +// //| VectorWithCopy | Default | 20 | Throughput | 16 | 356.050 ms | 12.3996 ms | 13.2675 ms | 336.000 ms | 381.900 ms | 356.417 ms | 260.50 | 10.13 | |
| 21 | +// //| NDArray | Default | 20 | Throughput | 16 | 73.999 ms | 1.7034 ms | 1.8227 ms | 71.696 ms | 77.212 ms | 73.811 ms | 54.14 | 1.40 | |
| 22 | +// //| SimpleArray | Default | 20 | Throughput | 16 | 1.366 ms | 0.0074 ms | 0.0082 ms | 1.356 ms | 1.385 ms | 1.366 ms | 1.00 | 0.00 | |
| 23 | +// //| ManualCopy | Default | 20 | Throughput | 16 | 7.345 ms | 0.0397 ms | 0.0408 ms | 7.286 ms | 7.423 ms | 7.348 ms | 5.37 | 0.04 | |
| 24 | +// //| MemoryCopy | Default | 20 | Throughput | 16 | 1.348 ms | 0.0261 ms | 0.0268 ms | 1.323 ms | 1.416 ms | 1.343 ms | 0.99 | 0.02 | |
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 GetSpanLargeLength |
31 |
| - { |
32 |
| - private const int length = 100_000; |
33 |
| - private const int iterations = 100; |
| 26 | +// [SimpleJob(RunStrategy.ColdStart, targetCount: 20)] |
| 27 | +// [SimpleJob(RunStrategy.Throughput, targetCount: 20)] |
| 28 | +// [MinColumn, MaxColumn, MeanColumn, MedianColumn] |
| 29 | +// [HtmlExporter] |
| 30 | +// public unsafe class GetSpanLargeLength |
| 31 | +// { |
| 32 | +// private const int length = 100_000; |
| 33 | +// private const int iterations = 100; |
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 |
| - // var vector = memoryTrash[i]; |
64 |
| - // if (vector == null) |
65 |
| - // break; |
66 |
| - // vector.Free(); |
67 |
| - // memoryTrash[i] = null; |
68 |
| - // } |
69 |
| - } |
| 58 | +// [BenchmarkDotNet.Attributes.IterationCleanup()] |
| 59 | +// public void Cleanup() |
| 60 | +// { |
| 61 | +// //if (memoryTrash != null) |
| 62 | +// // for (var i = 0; i < memoryTrash.Length; i++) { |
| 63 | +// // var vector = memoryTrash[i]; |
| 64 | +// // if (vector == null) |
| 65 | +// // break; |
| 66 | +// // vector.Free(); |
| 67 | +// // memoryTrash[i] = null; |
| 68 | +// // } |
| 69 | +// } |
70 | 70 |
|
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 | +// //} |
79 | 79 |
|
80 |
| - //UnmanagedByteStorage<int>[] memoryTrash; |
| 80 | +// //UnmanagedByteStorage<int>[] memoryTrash; |
81 | 81 |
|
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 | +// //} |
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