From a7f8cc9081ba8df39a810e5c848f1e5dc0c20b5d Mon Sep 17 00:00:00 2001 From: Anipik Date: Thu, 3 Jan 2019 13:47:43 -0800 Subject: [PATCH] iteration setup removed --- .../CacheDataViewBench.cs | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/test/Microsoft.ML.Benchmarks/CacheDataViewBench.cs b/test/Microsoft.ML.Benchmarks/CacheDataViewBench.cs index c2b1de8959..0888c5ea8c 100644 --- a/test/Microsoft.ML.Benchmarks/CacheDataViewBench.cs +++ b/test/Microsoft.ML.Benchmarks/CacheDataViewBench.cs @@ -14,9 +14,10 @@ public class CacheDataViewBench // Global. private IDataView _cacheDataView; - // Per iteration. private RowCursor _cursor; - private ValueGetter _getter; + private ValueGetter _seekerGetter; + private ValueGetter _cursorGetter; + private Schema.Column _col; private RowSeeker _seeker; private long[] _positions; @@ -57,30 +58,23 @@ public void Setup() var rand = new Random(0); for (int i = 0; i < _positions.Length; ++i) _positions[i] = rand.Next(Length); - } - [IterationSetup(Target = nameof(CacheWithCursor))] - public void CacheWithCursorSetup() - { - var col = _cacheDataView.Schema.GetColumnOrNull("A").Value; - _cursor = _cacheDataView.GetRowCursor(colIndex => colIndex == col.Index); - _getter = _cursor.GetGetter(col.Index); + _col = _cacheDataView.Schema.GetColumnOrNull("A").Value; + _seeker = ((IRowSeekable)_cacheDataView).GetSeeker(colIndex => colIndex == _col.Index); + _seekerGetter = _seeker.GetGetter(_col.Index); } [Benchmark] public void CacheWithCursor() { + // This setup takes very less time to execute as compared to the actual _cursorGetter. + // The most preferable position for this setup will be in GlobalSetup. + _cursor = _cacheDataView.GetRowCursor(colIndex => colIndex == _col.Index); + _cursorGetter = _cursor.GetGetter(_col.Index); + int val = 0; while (_cursor.MoveNext()) - _getter(ref val); - } - - [IterationSetup(Target = nameof(CacheWithSeeker))] - public void CacheWithSeekerSetup() - { - var col = _cacheDataView.Schema.GetColumnOrNull("A").Value; - _seeker = ((IRowSeekable)_cacheDataView).GetSeeker(colIndex => colIndex == col.Index); - _getter = _seeker.GetGetter(col.Index); + _cursorGetter(ref val); } [Benchmark] @@ -90,7 +84,7 @@ public void CacheWithSeeker() foreach (long pos in _positions) { _seeker.MoveTo(pos); - _getter(ref val); + _seekerGetter(ref val); } } }