< 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
 815    private int _stopRow = 150;
 816    private int _stopCol = 200;
 17
 418    public Common.PointCloud3 Points { get => _pCloud3; }
 19
 20    public void ComputeColRow(int idx, out int x, out int y)
 214775221    {
 214775222        x = idx % _width;
 214775223        y = idx / _width;
 214775224    }
 25
 26    public void ComputeIndex(int x, int y, out int index)
 217305227    {
 217305228        index = y * _width + x;
 217305229    }
 30
 431    public IterationMethods2()
 432    {
 433        var data = DataLoader.Load();
 434        Init(data.Item3, data.Item1, data.Item2);
 35
 436    }
 37
 438    public IterationMethods2(Point3[] data, int width, int height)
 439    {
 440        Init(data, width, height);
 441    }
 42
 43    private void Init(Point3[] data, int width, int height)
 844    {
 845        _width = width;
 846        _height = height;
 47
 848        _stopRow = (int)(0.66 * _height);
 849        _stopCol = (int)(0.75 * _width);
 50
 851        _pCloud3 = new Common.PointCloud3(_width, _height);
 852        _pCloud3.Update(data);
 853    }
 54
 55
 56    [Benchmark]
 57    public Tuple<float, int> Iterate2dIndexReconstruction()
 158    {
 159        var value = 0f;
 160        var n = 0;
 22261        for (var x = 0; x < _pCloud3.SizeX; x++)
 11062        {
 5082063            for (var y = 0; y < _pCloud3.SizeY; y++)
 2530064            {
 2530065                ComputeIndex(x, y, out var i);
 3768266                if (x < _stopCol && y < _stopRow) {
 1238267                    value += _pCloud3[i].Z;
 1238268                    n++;
 1238269                }
 2530070            }
 11071        }
 172        return new Tuple<float, int>(value, n);
 173    }
 74
 75    [Benchmark]
 76    public Tuple<float, int> Iterate2dIndex()
 177    {
 178        var value = 0f;
 179        var n = 0;
 22280        for (var x = 0; x < _pCloud3.SizeX; x++)
 11081        {
 5082082            for (var y = 0; y < _pCloud3.SizeY; y++)
 2530083            {
 3768284                if (x < _stopCol && y < _stopRow) {
 1238285                    value += _pCloud3[x, y].Z;
 1238286                    n++;
 1238287                }
 2530088            }
 89
 11090        }
 191        return new Tuple<float, int>(value, n);
 192    }
 93
 94    [Benchmark]
 95    public Tuple<float, int> IterateArray()
 196    {
 197        var value = 0f;
 198        var n = 0;
 199        var array = _pCloud3.AsArray();
 100
 222101        for (var x = 0; x < _pCloud3.SizeX; x++)
 110102        {
 50820103            for (var y = 0; y < _pCloud3.SizeY; y++)
 25300104            {
 25300105                ComputeIndex(x, y, out var i);
 37682106                if (x < _stopCol && y < _stopRow) {
 12382107                    value += array[i].Z;
 12382108                    n++;
 12382109                }
 25300110            }
 110111        }
 1112        return new Tuple<float, int>(value, n);
 1113    }
 114
 115    [Benchmark]
 116    public Tuple<float, int> IterateSpan()
 1117    {
 1118        var value = 0f;
 1119        var n = 0;
 1120        var span = _pCloud3.AsArray();
 222121        for (var x = 0; x < _pCloud3.SizeX; x++)
 110122        {
 50820123            for (var y = 0; y < _pCloud3.SizeY; y++)
 25300124            {
 25300125                ComputeIndex(x, y, out var i);
 37682126                if (x < _stopCol && y < _stopRow) {
 12382127                    value += span[i].Z;
 12382128                    n++;
 12382129                }
 25300130            }
 110131        }
 1132        return new Tuple<float, int>(value, n);
 1133    }
 134
 135    [Benchmark]
 136    public Tuple<float, int> IterateArrayCommutative()
 1137    {
 1138        var value = 0f;
 1139        var n = 0;
 1140        var array = _pCloud3.AsArray();
 141
 75902142        for (var i = 0; i < _pCloud3.Size; i++) {
 25300143            ComputeColRow(i, out var x, out var y);
 37682144            if (x < _stopCol && y < _stopRow) {
 12382145                value += array[i].Z;
 12382146                n++;
 12382147            }
 25300148        }
 1149        return new Tuple<float, int>(value, n);
 1150    }
 151
 152    [Benchmark]
 153    public Tuple<float, int> IterateJaggedArray()
 1154    {
 1155        var value = 0f;
 1156        var n = 0;
 1157        var array = _pCloud3.AsJaggedArray();
 222158        for (var x = 0; x < _pCloud3.SizeX; x++)
 110159        {
 50820160            for (var y = 0; y < _pCloud3.SizeY; y++)
 25300161            {
 37682162                if (x < _stopCol && y < _stopRow) {
 12382163                    value += array[x][y].Z;
 12382164                    n++;
 12382165                }
 25300166            }
 167
 110168        }
 1169        return new Tuple<float, int>(value, n);
 1170    }
 171
 172    [Benchmark]
 173    public Tuple<float, int> IterateSpanCommutative()
 1174    {
 1175        var value = 0f;
 1176        var n = 0;
 1177        var span = _pCloud3.AsSpan();
 50602178        for (var i = 0; i < _pCloud3.Size; i++)
 25300179        {
 25300180            ComputeColRow(i, out var x, out var y);
 25300181            if (x < _stopCol && y < _stopRow)
 12382182            {
 12382183                value += span[i].Z;
 12382184                n++;
 12382185            }
 25300186        }
 1187        return new Tuple<float, int>(value, n);
 1188    }
 189}