Skip to content

Commit 90f84f9

Browse files
committed
Add benchmark
1 parent 5bb23e9 commit 90f84f9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

docs/migration-guides/lodash/benchmark/benchmark.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,35 @@ bench( pkg+'::lodash:groupBy', opts, function benchmark( b ) {
171171
b.pass( 'benchmark finished' );
172172
b.end();
173173
});
174+
175+
bench( pkg+'::lodash:keyBy', opts, function benchmark( b ) {
176+
var arr;
177+
var out;
178+
var i;
179+
180+
function toKey( value ) {
181+
return value.name;
182+
}
183+
184+
arr = new Array( 100 );
185+
for ( i = 0; i < arr.length; i++ ) {
186+
arr[ i ] = {
187+
'name': 'v'+i,
188+
'value': i
189+
};
190+
}
191+
b.tic();
192+
for ( i = 0; i < b.iterations; i++ ) {
193+
arr[ 0 ].value = randu();
194+
out = _.keyBy( arr, toKey );
195+
if ( typeof out !== 'object' ) {
196+
b.fail( 'should return an object' );
197+
}
198+
}
199+
b.toc();
200+
if ( typeof out !== 'object' ) {
201+
b.fail( 'should return an object' );
202+
}
203+
b.pass( 'benchmark finished' );
204+
b.end();
205+
});

0 commit comments

Comments
 (0)