Skip to content

Commit 2d6960c

Browse files
committed
Add benchmark
1 parent f2cdb80 commit 2d6960c

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var bench = require( '@stdlib/bench' );
6+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
7+
var tryRequire = require( '@stdlib/utils/try-require' );
8+
var pkg = require( './../package.json' ).name;
9+
10+
11+
// VARIABLES //
12+
13+
var _ = tryRequire( 'lodash' );
14+
var opts = {
15+
'skip': ( _ instanceof Error )
16+
};
17+
18+
19+
// MAIN //
20+
21+
bench( pkg+'::lodash:each', opts, function benchmark( b ) {
22+
var arr;
23+
var i;
24+
25+
function onItem( v ) {
26+
if ( isnan( v ) ) {
27+
b.fail( 'should not be NaN' );
28+
}
29+
}
30+
31+
b.tic();
32+
for ( i = 0; i < b.iterations; i++ ) {
33+
arr = [ i, i+1, i+2, i+3, i+4 ];
34+
_.each( arr, onItem );
35+
if ( arr.length !== 5 ) {
36+
b.fail( 'should not change the array length' );
37+
}
38+
}
39+
b.toc();
40+
if ( arr.length !== 5 ) {
41+
b.fail( 'should not change the array length' );
42+
}
43+
b.pass( 'benchmark finished' );
44+
b.end();
45+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "stdlib-lodash-benchmarks",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Lodash benchmarks.",
6+
"license": "Apache-2.0",
7+
"author": {
8+
"name": "The Stdlib Authors",
9+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
10+
},
11+
"contributors": [
12+
{
13+
"name": "The Stdlib Authors",
14+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
15+
}
16+
],
17+
"main": "./benchmark/benchmark.js",
18+
"directories": {
19+
"benchmark": "./benchmark"
20+
},
21+
"scripts": {},
22+
"homepage": "https://github.com/stdlib-js/stdlib",
23+
"repository": {
24+
"type": "git",
25+
"url": "git://github.com/stdlib-js/stdlib.git"
26+
},
27+
"bugs": {
28+
"url": "https://github.com/stdlib-js/stdlib/issues"
29+
},
30+
"dependencies": {
31+
"lodash": "^4.17.4"
32+
},
33+
"devDependencies": {},
34+
"engines": {
35+
"node": ">=0.10.0",
36+
"npm": ">2.7.0"
37+
},
38+
"os": [
39+
"aix",
40+
"darwin",
41+
"freebsd",
42+
"linux",
43+
"macos",
44+
"openbsd",
45+
"sunos",
46+
"win32",
47+
"windows"
48+
],
49+
"keywords": [
50+
"stdlib",
51+
"benchmarks",
52+
"benchmark",
53+
"performance",
54+
"lodash",
55+
"underscore"
56+
],
57+
"__stdlib__": {}
58+
}

0 commit comments

Comments
 (0)