mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Avoid expensive test setup in perf.js.
Former-commit-id: f1c1ed41cb86c83aba2c3f7da1dedf6a280221ad
This commit is contained in:
64
perf/perf.js
64
perf/perf.js
@@ -81,28 +81,32 @@
|
|||||||
_ = window._,
|
_ = window._,
|
||||||
lodash = window.lodash;
|
lodash = window.lodash;
|
||||||
|
|
||||||
var length = 20,
|
var index,
|
||||||
funcNames = lodash.functions(lodash),
|
length,
|
||||||
numbers = [],
|
belt = /Lo-Dash/.test(this.name) ? lodash : _,
|
||||||
|
limit = 20,
|
||||||
|
numbers = Array(limit),
|
||||||
object = {},
|
object = {},
|
||||||
|
objects = Array(limit),
|
||||||
fourNumbers = [5, 25, 10, 30],
|
fourNumbers = [5, 25, 10, 30],
|
||||||
nestedNumbers = [1, [2], [3, [[4]]]],
|
nestedNumbers = [1, [2], [3, [[4]]]],
|
||||||
twoNumbers = [12, 21];
|
twoNumbers = [12, 21];
|
||||||
|
|
||||||
var bindAllObjects = [];
|
for (index = 0, length = limit; index < length; index++) {
|
||||||
|
|
||||||
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;
|
numbers[index] = index;
|
||||||
object['key' + index] = index;
|
object['key' + index] = index;
|
||||||
});
|
objects[index] = { 'num': index };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof isBindAll != 'undefined') {
|
||||||
|
var bindAllObjects = Array(this.count),
|
||||||
|
funcNames = belt.functions(lodash);
|
||||||
|
|
||||||
|
// potentially expensive
|
||||||
|
for (index = 0, length = this.count; index < length; index++) {
|
||||||
|
bindAllObjects[index] = belt.clone(lodash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ctor = function() { };
|
var ctor = function() { };
|
||||||
|
|
||||||
@@ -234,7 +238,7 @@
|
|||||||
'twenty-five': 25
|
'twenty-five': 25
|
||||||
};
|
};
|
||||||
|
|
||||||
var words = _.keys(wordToNumber).slice(0, length);
|
var words = belt.keys(wordToNumber).slice(0, limit);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -361,21 +365,33 @@
|
|||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.bindAll` iterating arguments')
|
Benchmark.Suite('`_.bindAll` iterating arguments')
|
||||||
.add('Lo-Dash', function() {
|
.add('Lo-Dash', {
|
||||||
lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames));
|
'fn': function() {
|
||||||
|
lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames));
|
||||||
|
},
|
||||||
|
'teardown': 'function isBindAll(){}'
|
||||||
})
|
})
|
||||||
.add('Underscore', function() {
|
.add('Underscore', {
|
||||||
_.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames));
|
'fn': function() {
|
||||||
|
_.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames));
|
||||||
|
},
|
||||||
|
'teardown': 'function isBindAll(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.bindAll` iterating the `object`')
|
Benchmark.Suite('`_.bindAll` iterating the `object`')
|
||||||
.add('Lo-Dash', function() {
|
.add('Lo-Dash', {
|
||||||
lodash.bindAll(bindAllObjects.pop());
|
'fn': function() {
|
||||||
|
lodash.bindAll(bindAllObjects.pop());
|
||||||
|
},
|
||||||
|
'teardown': 'function isBindAll(){}'
|
||||||
})
|
})
|
||||||
.add('Underscore', function() {
|
.add('Underscore', {
|
||||||
_.bindAll(bindAllObjects.pop());
|
'fn': function() {
|
||||||
|
_.bindAll(bindAllObjects.pop());
|
||||||
|
},
|
||||||
|
'teardown': 'function isBindAll(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user