Advertisement
elibelash

Untitled

Oct 9th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System.Linq;
  2. using BenchmarkDotNet.Attributes;
  3. using BenchmarkDotNet.Engines;
  4. using NumSharp.Backends;
  5. using NumSharp.Backends.Unmanaged;
  6. using NumSharp.Memory.Pooling;
  7. using NumSharp.Unmanaged.Memory;
  8. using NumSharp.Utilities;
  9.  
  10. namespace NumSharp.Benchmark.Unmanaged
  11. {
  12.     //|            Method |       Mean |    Error |   StdDev |     Median |        Min |        Max | Ratio | RatioSD |
  13.     //|------------------ |-----------:|---------:|---------:|-----------:|-----------:|-----------:|------:|--------:|
  14.     //| OffsetIncrementor | 1,049.5 us | 6.060 us | 82.25 us | 1,030.6 us | 1,006.9 us | 2,119.3 us |  1.42 |    0.15 |
  15.     //|         GetOffset |   745.3 us | 6.163 us | 83.64 us |   728.0 us |   685.1 us | 2,746.7 us |  1.00 |    0.00 |
  16.  
  17.     [SimpleJob(RunStrategy.ColdStart, targetCount: 2000)]
  18.     [MinColumn, MaxColumn, MeanColumn, MedianColumn]
  19.     [HtmlExporter]
  20.     public class Iterators
  21.     {
  22.         private Shape shape;
  23.         private NDIterator<int> iter;
  24.         private NDArray ndarray;
  25.  
  26.         [GlobalSetup]
  27.         public void Setup()
  28.         {
  29.             var _ = ScalarMemoryPool.Instance;
  30.             var __ = InfoOf<byte>.Size;
  31.             shape = new Shape(2, 1, 50_000);
  32.             ndarray = np.array(Enumerable.Range(0, 100_000).ToArray()).reshape(ref shape);
  33.             iter = new NDIterator<int>((IMemoryBlock<int>)ndarray.Array, shape, null);
  34.         }
  35.  
  36.         [IterationCleanup]
  37.         public void Reset()
  38.         {
  39.             iter.Reset();
  40.         }
  41.  
  42.         [Benchmark]
  43.         public void OffsetIncrementor()
  44.         {
  45.             var next = iter.MoveNext;
  46.             for (int i = 0; i < 100_000; i++)
  47.             {
  48.                 next();
  49.             }
  50.         }
  51.  
  52.         [Benchmark(Baseline = true)]
  53.         public void GetOffset()
  54.         {
  55.             for (int j = 0; j < 2; j++)
  56.             {
  57.                 for (int i = 0; i < 50_000; i++)
  58.                 {
  59.                     ndarray.GetInt32(j, 0, i);
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement