mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Add _.bind and _.size benchmarks.
Former-commit-id: bb3517e9517db81de56e3794abc256cd2dac59b5
This commit is contained in:
53
perf/perf.js
53
perf/perf.js
@@ -76,8 +76,11 @@
|
|||||||
nestedNumbers = [1, [2], [3, [[4]]]],
|
nestedNumbers = [1, [2], [3, [[4]]]],
|
||||||
twoNumbers = [12, 21];
|
twoNumbers = [12, 21];
|
||||||
|
|
||||||
var ctor = function() { },
|
var ctor = function() { };
|
||||||
func = function(greeting) { return greeting + ': ' + this.name; };
|
|
||||||
|
var func = function(greeting, punctuation) {
|
||||||
|
return greeting + ', ' + this.name + (punctuation || '.');
|
||||||
|
};
|
||||||
|
|
||||||
var lodashBoundNormal = lodash.bind(func, { 'name': 'moe' }),
|
var lodashBoundNormal = lodash.bind(func, { 'name': 'moe' }),
|
||||||
lodashBoundCtor = lodash.bind(ctor, { 'name': 'moe' }),
|
lodashBoundCtor = lodash.bind(ctor, { 'name': 'moe' }),
|
||||||
@@ -184,7 +187,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
suites.push(
|
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() {
|
.add('Lo-Dash', function() {
|
||||||
lodash.bind(func, { 'name': 'moe' }, 'hi');
|
lodash.bind(func, { 'name': 'moe' }, 'hi');
|
||||||
})
|
})
|
||||||
@@ -204,7 +207,17 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
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() {
|
.add('Lo-Dash', function() {
|
||||||
lodashBoundPartial();
|
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(
|
suites.push(
|
||||||
Benchmark.Suite('bound and called in a `new` expression, i.e. `new bound` (edge case)')
|
Benchmark.Suite('bound and called in a `new` expression, i.e. `new bound` (edge case)')
|
||||||
.add('Lo-Dash', function() {
|
.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(
|
suites.push(
|
||||||
Benchmark.Suite('`_.sortBy` with `callback`')
|
Benchmark.Suite('`_.sortBy` with `callback`')
|
||||||
.add('Lo-Dash', function() {
|
.add('Lo-Dash', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user