@@ -14,9 +14,10 @@ public class CacheDataViewBench
1414
1515 // Global.
1616 private IDataView _cacheDataView ;
17- // Per iteration.
1817 private RowCursor _cursor ;
19- private ValueGetter < int > _getter ;
18+ private ValueGetter < int > _seekerGetter ;
19+ private ValueGetter < int > _cursorGetter ;
20+ private Schema . Column _col ;
2021
2122 private RowSeeker _seeker ;
2223 private long [ ] _positions ;
@@ -57,30 +58,23 @@ public void Setup()
5758 var rand = new Random ( 0 ) ;
5859 for ( int i = 0 ; i < _positions . Length ; ++ i )
5960 _positions [ i ] = rand . Next ( Length ) ;
60- }
6161
62- [ IterationSetup ( Target = nameof ( CacheWithCursor ) ) ]
63- public void CacheWithCursorSetup ( )
64- {
65- var col = _cacheDataView . Schema . GetColumnOrNull ( "A" ) . Value ;
66- _cursor = _cacheDataView . GetRowCursor ( colIndex => colIndex == col . Index ) ;
67- _getter = _cursor . GetGetter < int > ( col . Index ) ;
62+ _col = _cacheDataView . Schema . GetColumnOrNull ( "A" ) . Value ;
63+ _seeker = ( ( IRowSeekable ) _cacheDataView ) . GetSeeker ( colIndex => colIndex == _col . Index ) ;
64+ _seekerGetter = _seeker . GetGetter < int > ( _col . Index ) ;
6865 }
6966
7067 [ Benchmark ]
7168 public void CacheWithCursor ( )
7269 {
70+ // This setup takes very less time to execute as compared to the actual _cursorGetter.
71+ // The most preferable position for this setup will be in GlobalSetup.
72+ _cursor = _cacheDataView . GetRowCursor ( colIndex => colIndex == _col . Index ) ;
73+ _cursorGetter = _cursor . GetGetter < int > ( _col . Index ) ;
74+
7375 int val = 0 ;
7476 while ( _cursor . MoveNext ( ) )
75- _getter ( ref val ) ;
76- }
77-
78- [ IterationSetup ( Target = nameof ( CacheWithSeeker ) ) ]
79- public void CacheWithSeekerSetup ( )
80- {
81- var col = _cacheDataView . Schema . GetColumnOrNull ( "A" ) . Value ;
82- _seeker = ( ( IRowSeekable ) _cacheDataView ) . GetSeeker ( colIndex => colIndex == col . Index ) ;
83- _getter = _seeker . GetGetter < int > ( col . Index ) ;
77+ _cursorGetter ( ref val ) ;
8478 }
8579
8680 [ Benchmark ]
@@ -90,7 +84,7 @@ public void CacheWithSeeker()
9084 foreach ( long pos in _positions )
9185 {
9286 _seeker . MoveTo ( pos ) ;
93- _getter ( ref val ) ;
87+ _seekerGetter ( ref val ) ;
9488 }
9589 }
9690 }
0 commit comments