Avoid enforcing strict mode in _.defaults, _.extend, and _.bindAll and add benchmarks for _.bindAll and _.functions. [closes #45]

Former-commit-id: 1bb0b5155d3ae46052b4a06cb538dff307e8ec5e
This commit is contained in:
John-David Dalton
2012-07-12 15:25:18 -04:00
parent 9530efb4d4
commit 3386c2a7a5
6 changed files with 137 additions and 63 deletions

View File

@@ -82,12 +82,28 @@
lodash = window.lodash;
var length = 20,
funcNames = lodash.functions(lodash),
numbers = [],
object = {},
fourNumbers = [5, 25, 10, 30],
nestedNumbers = [1, [2], [3, [[4]]]],
twoNumbers = [12, 21];
var bindAllObjects = [];
var objects = lodash.map(numbers, function(num) {
return { 'num': num };
});
lodash.times(this.count, function(index) {
bindAllObjects[index] = lodash.clone(lodash);
});
lodash.times(length, function(index) {
numbers[index] = index;
object['key' + index] = index;
});
var ctor = function() { };
var func = function(greeting, punctuation) {
@@ -219,15 +235,6 @@
};
var words = _.keys(wordToNumber).slice(0, length);
for (var index = 0; index < length; index++) {
numbers[index] = index;
object['key' + index] = index;
}
var objects = lodash.map(numbers, function(num) {
return { 'num': num };
});
}
});
@@ -352,6 +359,28 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.bindAll` iterating arguments')
.add('Lo-Dash', function() {
lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames));
})
.add('Underscore', function() {
_.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames));
})
);
suites.push(
Benchmark.Suite('`_.bindAll` iterating the `object`')
.add('Lo-Dash', function() {
lodash.bindAll(bindAllObjects.pop());
})
.add('Underscore', function() {
_.bindAll(bindAllObjects.pop());
})
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.each` iterating an array')
.add('Lo-Dash', function() {
@@ -498,6 +527,18 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.functions`')
.add('Lo-Dash', function() {
lodash.functions(lodash);
})
.add('Underscore', function() {
_.functions(lodash);
})
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.difference`')
.add('Lo-Dash', function() {