Add _.bind and _.size benchmarks.

Former-commit-id: bb3517e9517db81de56e3794abc256cd2dac59b5
This commit is contained in:
John-David Dalton
2012-07-02 00:07:55 -04:00
parent 3b4074bfc7
commit 268ce91c65

View File

@@ -76,8 +76,11 @@
nestedNumbers = [1, [2], [3, [[4]]]],
twoNumbers = [12, 21];
var ctor = function() { },
func = function(greeting) { return greeting + ': ' + this.name; };
var ctor = function() { };
var func = function(greeting, punctuation) {
return greeting + ', ' + this.name + (punctuation || '.');
};
var lodashBoundNormal = lodash.bind(func, { 'name': 'moe' }),
lodashBoundCtor = lodash.bind(ctor, { 'name': 'moe' }),
@@ -184,7 +187,7 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.bind` (will use native if available and inferred fast)')
Benchmark.Suite('`_.bind` (uses native `Function#bind` if available and inferred fast)')
.add('Lo-Dash', function() {
lodash.bind(func, { 'name': 'moe' }, 'hi');
})
@@ -204,7 +207,17 @@
);
suites.push(
Benchmark.Suite('bound and partially applied call')
Benchmark.Suite('bound call with arguments')
.add('Lo-Dash', function() {
lodashBoundNormal('hi', '!');
})
.add('Underscore', function() {
_boundNormal('hi', '!');
})
);
suites.push(
Benchmark.Suite('bound and partially applied call (uses native `Function#bind` if available)')
.add('Lo-Dash', function() {
lodashBoundPartial();
})
@@ -213,6 +226,16 @@
})
);
suites.push(
Benchmark.Suite('bound and partially applied call with arguments (uses native `Function#bind` if available)')
.add('Lo-Dash', function() {
lodashBoundPartial('!');
})
.add('Underscore', function() {
_boundPartial('!');
})
);
suites.push(
Benchmark.Suite('bound and called in a `new` expression, i.e. `new bound` (edge case)')
.add('Lo-Dash', function() {
@@ -491,6 +514,28 @@
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.size` with an array')
.add('Lo-Dash', function() {
lodash.size(numbers);
})
.add('Underscore', function() {
_.size(numbers);
})
);
suites.push(
Benchmark.Suite('`_.size` with an object')
.add('Lo-Dash', function() {
lodash.size(object);
})
.add('Underscore', function() {
_.size(object);
})
);
/*--------------------------------------------------------------------------*/
suites.push(
Benchmark.Suite('`_.sortBy` with `callback`')
.add('Lo-Dash', function() {