| | | 1 | | using BenchmarkDotNet.Attributes; |
| | | 2 | | using PointCloud.Benchmark.Util; |
| | | 3 | | using ReFlex.Core.Common.Components; |
| | | 4 | | using ArrayUtils = PointCloud.Benchmark.Common.ArrayUtils; |
| | | 5 | | |
| | | 6 | | namespace PointCloud.Benchmark.Benchmarks.UpdatePointCloud; |
| | | 7 | | |
| | | 8 | | public class CopyPointCloud |
| | | 9 | | { |
| | | 10 | | private int _width; |
| | | 11 | | private int _height; |
| | | 12 | | |
| | | 13 | | private PointCloud3 _pCloud3; |
| | | 14 | | |
| | | 15 | | private Point3[] _data; |
| | | 16 | | private readonly Point3[] _array; |
| | | 17 | | private readonly Point3[][] _jaggedArray; |
| | | 18 | | |
| | 0 | 19 | | public CopyPointCloud() |
| | 0 | 20 | | { |
| | 0 | 21 | | var data = DataLoader.Load(); |
| | 0 | 22 | | _width = data.Item1; |
| | 0 | 23 | | _height = data.Item2; |
| | | 24 | | |
| | | 25 | | |
| | 0 | 26 | | _pCloud3 = new PointCloud3(_width, _height); |
| | 0 | 27 | | _data = data.Item3; |
| | | 28 | | |
| | 0 | 29 | | _array = _pCloud3.AsArray(); |
| | 0 | 30 | | _jaggedArray = _pCloud3.AsJaggedArray(); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | [Benchmark] |
| | | 34 | | public void Copy() |
| | 0 | 35 | | { |
| | 0 | 36 | | var copy = new PointCloud3(_pCloud3.SizeX, _pCloud3.SizeY); |
| | 0 | 37 | | copy.Update(_pCloud3.AsArray(), 0f); |
| | 0 | 38 | | _pCloud3 = copy; |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | [Benchmark] |
| | | 42 | | public void Init1d() |
| | 0 | 43 | | { |
| | 0 | 44 | | ArrayUtils.InitializeArray(out Point3[] init, _pCloud3.Size); |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | [Benchmark] |
| | | 48 | | public void Init2d() |
| | 0 | 49 | | { |
| | 0 | 50 | | ArrayUtils.InitializeArray(out Point3[][] init, _pCloud3.SizeX, _pCloud3.SizeY); |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | [Benchmark] |
| | | 54 | | public void Init1dSpan() |
| | 0 | 55 | | { |
| | 0 | 56 | | ArrayUtils.InitializeSpan(out Span<Point3> init, _pCloud3.Size); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | [Benchmark] |
| | | 60 | | public void Init2dSpan() |
| | 0 | 61 | | { |
| | 0 | 62 | | ArrayUtils.InitializeSpan(out Span<Point3[]> init, _pCloud3.SizeX, _pCloud3.SizeY); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | [Benchmark] |
| | | 66 | | public void Ref() |
| | 0 | 67 | | { |
| | 0 | 68 | | ArrayUtils.ReferencingArrays(_array, _jaggedArray); |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | [Benchmark] |
| | | 72 | | public void RefSpan() |
| | 0 | 73 | | { |
| | 0 | 74 | | ArrayUtils.ReferencingArrays(_array.AsSpan(), _jaggedArray.AsSpan()); |
| | 0 | 75 | | } |
| | | 76 | | } |