< Summary - ReFlex - Library

Information
Class: PointCloud.Benchmark.Benchmarks.IteratePointCloud.IterationMethods2
Assembly: ReFlex.PointCloud.Benchmark
File(s): D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Benchmarks\IteratePointCloud\IterationMethods2.cs
Line coverage
100%
Covered lines: 136
Uncovered lines: 0
Coverable lines: 136
Total lines: 189
Line coverage: 100%
Branch coverage
100%
Covered branches: 52
Total branches: 52
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Points()100%11100%
ComputeColRow(...)100%11100%
ComputeIndex(...)100%11100%
.ctor(...)100%11100%
Init(...)100%11100%
Iterate2dIndexReconstruction()100%88100%
Iterate2dIndex()100%88100%
IterateArray()100%88100%
IterateSpan()100%88100%
IterateArrayCommutative()100%66100%
IterateJaggedArray()100%88100%
IterateSpanCommutative()100%66100%

File(s)

D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Benchmarks\IteratePointCloud\IterationMethods2.cs

#LineLine coverage
 1using BenchmarkDotNet.Attributes;
 2using PointCloud.Benchmark.Util;
 3using ReFlex.Core.Common.Components;
 4
 5namespace PointCloud.Benchmark.Benchmarks.IteratePointCloud;
 6
 7[MemoryDiagnoser]
 8public class IterationMethods2
 9{
 10    private int _width;
 11    private int _height;
 12
 13    private Common.PointCloud3 _pCloud3;
 14
 1615    private int _stopRow = 150;
 1616    private int _stopCol = 200;
 17
 818    public Common.PointCloud3 Points { get => _pCloud3; }
 19
 20    public void ComputeColRow(int idx, out int x, out int y)
 429550421    {
 429550422        x = idx % _width;
 429550423        y = idx / _width;
 429550424    }
 25
 26    public void ComputeIndex(int x, int y, out int index)
 434610427    {
 434610428        index = y * _width + x;
 434610429    }
 30
 831    public IterationMethods2()
 832    {
 833        var data = DataLoader.Load();
 834        Init(data.Item3, data.Item1, data.Item2);
 35
 836    }
 37
 838    public IterationMethods2(Point3[] data, int width, int height)
 839    {
 840        Init(data, width, height);
 841    }
 42
 43    private void Init(Point3[] data, int width, int height)
 1644    {
 1645        _width = width;
 1646        _height = height;
 47
 1648        _stopRow = (int)(0.66 * _height);
 1649        _stopCol = (int)(0.75 * _width);
 50
 1651        _pCloud3 = new Common.PointCloud3(_width, _height);
 1652        _pCloud3.Update(data);
 1653    }
 54
 55
 56    [Benchmark]
 57    public Tuple<float, int> Iterate2dIndexReconstruction()
 258    {
 259        var value = 0f;
 260        var n = 0;
 44461        for (var x = 0; x < _pCloud3.SizeX; x++)
 22062        {
 10164063            for (var y = 0; y < _pCloud3.SizeY; y++)
 5060064            {
 5060065                ComputeIndex(x, y, out var i);
 7536466                if (x < _stopCol && y < _stopRow) {
 2476467                    value += _pCloud3[i].Z;
 2476468                    n++;
 2476469                }
 5060070            }
 22071        }
 272        return new Tuple<float, int>(value, n);
 273    }
 74
 75    [Benchmark]
 76    public Tuple<float, int> Iterate2dIndex()
 277    {
 278        var value = 0f;
 279        var n = 0;
 44480        for (var x = 0; x < _pCloud3.SizeX; x++)
 22081        {
 10164082            for (var y = 0; y < _pCloud3.SizeY; y++)
 5060083            {
 7536484                if (x < _stopCol && y < _stopRow) {
 2476485                    value += _pCloud3[x, y].Z;
 2476486                    n++;
 2476487                }
 5060088            }
 89
 22090        }
 291        return new Tuple<float, int>(value, n);
 292    }
 93
 94    [Benchmark]
 95    public Tuple<float, int> IterateArray()
 296    {
 297        var value = 0f;
 298        var n = 0;
 299        var array = _pCloud3.AsArray();
 100
 444101        for (var x = 0; x < _pCloud3.SizeX; x++)
 220102        {
 101640103            for (var y = 0; y < _pCloud3.SizeY; y++)
 50600104            {
 50600105                ComputeIndex(x, y, out var i);
 75364106                if (x < _stopCol && y < _stopRow) {
 24764107                    value += array[i].Z;
 24764108                    n++;
 24764109                }
 50600110            }
 220111        }
 2112        return new Tuple<float, int>(value, n);
 2113    }
 114
 115    [Benchmark]
 116    public Tuple<float, int> IterateSpan()
 2117    {
 2118        var value = 0f;
 2119        var n = 0;
 2120        var span = _pCloud3.AsArray();
 444121        for (var x = 0; x < _pCloud3.SizeX; x++)
 220122        {
 101640123            for (var y = 0; y < _pCloud3.SizeY; y++)
 50600124            {
 50600125                ComputeIndex(x, y, out var i);
 75364126                if (x < _stopCol && y < _stopRow) {
 24764127                    value += span[i].Z;
 24764128                    n++;
 24764129                }
 50600130            }
 220131        }
 2132        return new Tuple<float, int>(value, n);
 2133    }
 134
 135    [Benchmark]
 136    public Tuple<float, int> IterateArrayCommutative()
 2137    {
 2138        var value = 0f;
 2139        var n = 0;
 2140        var array = _pCloud3.AsArray();
 141
 151804142        for (var i = 0; i < _pCloud3.Size; i++) {
 50600143            ComputeColRow(i, out var x, out var y);
 75364144            if (x < _stopCol && y < _stopRow) {
 24764145                value += array[i].Z;
 24764146                n++;
 24764147            }
 50600148        }
 2149        return new Tuple<float, int>(value, n);
 2150    }
 151
 152    [Benchmark]
 153    public Tuple<float, int> IterateJaggedArray()
 2154    {
 2155        var value = 0f;
 2156        var n = 0;
 2157        var array = _pCloud3.AsJaggedArray();
 444158        for (var x = 0; x < _pCloud3.SizeX; x++)
 220159        {
 101640160            for (var y = 0; y < _pCloud3.SizeY; y++)
 50600161            {
 75364162                if (x < _stopCol && y < _stopRow) {
 24764163                    value += array[x][y].Z;
 24764164                    n++;
 24764165                }
 50600166            }
 167
 220168        }
 2169        return new Tuple<float, int>(value, n);
 2170    }
 171
 172    [Benchmark]
 173    public Tuple<float, int> IterateSpanCommutative()
 2174    {
 2175        var value = 0f;
 2176        var n = 0;
 2177        var span = _pCloud3.AsSpan();
 101204178        for (var i = 0; i < _pCloud3.Size; i++)
 50600179        {
 50600180            ComputeColRow(i, out var x, out var y);
 50600181            if (x < _stopCol && y < _stopRow)
 24764182            {
 24764183                value += span[i].Z;
 24764184                n++;
 24764185            }
 50600186        }
 2187        return new Tuple<float, int>(value, n);
 2188    }
 189}