Skip to content

Commit 68cddfb

Browse files
committed
Add iteration benchmark
1 parent c19c070 commit 68cddfb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/node_modules/@stdlib/iter/flow/benchmark/benchmark.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' );
2424
var isFunction = require( '@stdlib/assert/is-function' );
2525
var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
2626
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var randu = require( '@stdlib/random/iter/randu' );
2829
var iterHead = require( '@stdlib/iter/head' );
2930
var iterSomeBy = require( '@stdlib/iter/some-by' );
@@ -112,6 +113,36 @@ bench( pkg+'::constructor,no_new', function benchmark( b ) {
112113
b.end();
113114
});
114115

116+
bench( pkg+'::iteration', function benchmark( b ) {
117+
var FluentIterator;
118+
var src;
119+
var it;
120+
var z;
121+
var i;
122+
123+
FluentIterator = iterFlow({
124+
'head': iterHead,
125+
'someBy': iterSomeBy
126+
});
127+
128+
src = randu();
129+
it = new FluentIterator( src );
130+
131+
b.tic();
132+
for ( i = 0; i < b.iterations; i++ ) {
133+
z = it.next().value;
134+
if ( isnan( z ) ) {
135+
b.fail( 'should not return NaN' );
136+
}
137+
}
138+
b.toc();
139+
if ( isnan( z ) ) {
140+
b.fail( 'should not return NaN' );
141+
}
142+
b.pass( 'benchmark finished' );
143+
b.end();
144+
});
145+
115146
bench( pkg+'::pipeline_throughput', function benchmark( b ) {
116147
var FluentIterator;
117148
var bool;

0 commit comments

Comments
 (0)