Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions test/Microsoft.ML.Benchmarks/CacheDataViewBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class CacheDataViewBench

// Global.
private IDataView _cacheDataView;
// Per iteration.
private RowCursor _cursor;
private ValueGetter<int> _getter;
private ValueGetter<int> _seekerGetter;
private ValueGetter<int> _cursorGetter;
private Schema.Column _col;

private RowSeeker _seeker;
private long[] _positions;
Expand Down Expand Up @@ -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<int>(col.Index);
_col = _cacheDataView.Schema.GetColumnOrNull("A").Value;
_seeker = ((IRowSeekable)_cacheDataView).GetSeeker(colIndex => colIndex == _col.Index);
_seekerGetter = _seeker.GetGetter<int>(_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<int>(_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<int>(col.Index);
_cursorGetter(ref val);
}

[Benchmark]
Expand All @@ -90,7 +84,7 @@ public void CacheWithSeeker()
foreach (long pos in _positions)
{
_seeker.MoveTo(pos);
_getter(ref val);
_seekerGetter(ref val);
}
}
}
Expand Down