Skip to content

Commit 01ad0e6

Browse files
committed
Update benchmark
1 parent e0aaf26 commit 01ad0e6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ function createIterator( arr ) {
4242
return it;
4343

4444
function next() {
45+
if ( i === len ) {
46+
i = -1;
47+
}
4548
i += 1;
46-
if ( i < len-1 ) {
49+
if ( i < len ) {
4750
return {
4851
'value': arr[ i ],
4952
'done': false
5053
};
5154
}
52-
i = -1; // reset index
5355
return {
54-
'value': arr[ len-1 ],
5556
'done': true
5657
};
5758
}
@@ -86,6 +87,7 @@ bench( pkg+'::loop', function benchmark( b ) {
8687
var values;
8788
var arr;
8889
var v;
90+
var p;
8991
var i;
9092

9193
values = [ 0, 0, 0, 0, 0, 1 ];
@@ -95,14 +97,15 @@ bench( pkg+'::loop', function benchmark( b ) {
9597
for ( i = 0; i < b.iterations; i++ ) {
9698
v = {};
9799
while ( v && !v.done ) {
100+
p = v;
98101
v = arr.next();
99102
}
100-
if ( v.value !== 1 ) {
103+
if ( p.value !== 1 ) {
101104
b.fail( 'unexpected result' );
102105
}
103106
}
104107
b.toc();
105-
if ( v.value !== 1 ) {
108+
if ( p.value !== 1 ) {
106109
b.fail( 'unexpected result' );
107110
}
108111
b.pass( 'benchmark finished' );

0 commit comments

Comments
 (0)