Skip to content

Commit 56fad2e

Browse files
committed
update benchmarks
1 parent 16af7cd commit 56fad2e

28 files changed

+2991
-124
lines changed

benchmark/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# benchmarks
2+
3+
Run the benchmarks:
4+
5+
```sh
6+
$ node benchmark
7+
```
8+
9+
Do a dry run to check results of functions:
10+
11+
```sh
12+
$ node benchmark/check.js
13+
```

benchmark/check.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
'use strict';
22

33
var fs = require('fs');
4-
var chalk = require('chalk');
4+
var bold = require('ansi-bold');
55
var path = require('path');
66

77
/**
88
* Sanity check. run to ensure that all fns return a correct
99
* result. Otherwise benchmarks are (even more) useless
1010
*/
1111

12-
fs.readdirSync(__dirname + '/code').forEach(function (fp) {
12+
fs.readdirSync(__dirname + '/code').forEach(function(fp) {
1313
var fn = require(path.resolve(__dirname, 'code', fp));
1414
var name = path.basename(fp, path.extname(fp));
1515

16-
fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
16+
fs.readdirSync(__dirname + '/fixtures').forEach(function(fixture) {
1717
fixture = path.resolve(__dirname, 'fixtures', fixture);
1818
if (/\.js$/.test(fixture)) {
19-
console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)));
19+
console.log(bold(name) + ':', fn.apply(null, require(fixture)).length);
2020
}
2121
});
2222
});

benchmark/code/array-differ.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict';
22

3-
module.exports = require('array-differ');
3+
module.exports = require('array-differ');

benchmark/code/current.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict';
22

3-
module.exports = require('../..');
3+
module.exports = require('../..');

benchmark/code/filter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
module.exports = function diff(a, b) {
4-
return a.filter(function (value) {
5-
return (b.indexOf(value) === -1);
3+
module.exports = function diff(arr, arrays) {
4+
arrays = [].concat.apply([], [].slice.call(arguments, 1));
5+
return arr.filter(function(ele) {
6+
return arrays.indexOf(ele) === -1;
67
});
78
};

benchmark/code/for-lefthand.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

benchmark/code/for-negative.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
'use strict';
22

3-
var diff = module.exports = function diff(a, b) {
4-
var arr = [];
3+
module.exports = function diff(arr, arrays) {
4+
arrays = [].concat.apply([], [].slice.call(arguments, 1));
55

6-
for (var i = a.length - 1; i >= 0; i--) {
7-
var key = a[i];
8-
if (-1 === b.indexOf(key)) {
9-
arr.push(key);
6+
var len = arr.length - 1;
7+
var result = [];
8+
9+
for (var i = len; i >= 0; i--) {
10+
var ele = arr[i];
11+
if (arrays.indexOf(ele) === -1) {
12+
result.push(ele);
1013
}
1114
}
12-
return arr;
15+
return result;
1316
};

benchmark/code/for-reverse.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

benchmark/code/for.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
'use strict';
22

3-
module.exports = function diff(a, b) {
4-
var len = a.length;
5-
var arr = [];
3+
module.exports = function diff(arr, arrays) {
4+
arrays = [].concat.apply([], [].slice.call(arguments, 1));
5+
6+
var len = arr.length;
7+
var result = [];
68

79
for (var i = 0; i < len; i++) {
8-
if (b.indexOf(a[i]) === -1) {
9-
arr.push(a[i]);
10+
var ele = arr[i];
11+
if (arrays.indexOf(ele) === -1) {
12+
result.push(ele);
1013
}
1114
}
12-
return arr;
15+
return result;
1316
};

benchmark/code/forEach-2.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)