mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Cleanup perf tests and adjust for LARGE_ARRAY_SIZE of 40.
This commit is contained in:
164
perf/perf.js
164
perf/perf.js
@@ -1,27 +1,52 @@
|
|||||||
;(function(root) {
|
;(function() {
|
||||||
|
|
||||||
|
/** Used as a safe reference for `undefined` in pre ES5 environments */
|
||||||
|
var undefined;
|
||||||
|
|
||||||
|
/** Used as a reference to the global object */
|
||||||
|
var root = typeof global == 'object' && global || this;
|
||||||
|
|
||||||
|
/** Method and object shortcuts */
|
||||||
|
var phantom = root.phantom,
|
||||||
|
amd = root.define && define.amd,
|
||||||
|
argv = root.process && process.argv,
|
||||||
|
document = !phantom && root.document,
|
||||||
|
noop = function() {},
|
||||||
|
params = root.arguments,
|
||||||
|
system = root.system;
|
||||||
|
|
||||||
|
/** Detect if running in Java */
|
||||||
|
var isJava = !document && !!root.java;
|
||||||
|
|
||||||
/** Use a single "load" function */
|
/** Use a single "load" function */
|
||||||
var load = typeof require == 'function' ? require : root.load;
|
var load = (typeof require == 'function' && !amd)
|
||||||
|
? require
|
||||||
|
: (isJava && root.load) || noop;
|
||||||
|
|
||||||
/** The file path of the Lo-Dash file to test */
|
/** The file path of the Lo-Dash file to test */
|
||||||
var filePath = (function() {
|
var filePath = (function() {
|
||||||
var min = 0;
|
var min = 0,
|
||||||
var result = root.phantom
|
result = [];
|
||||||
? phantom.args
|
|
||||||
: (root.system
|
|
||||||
? (min = 1, system.args)
|
|
||||||
: (root.process ? (min = 2, process.argv) : (root.arguments || []))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if (phantom) {
|
||||||
|
result = params = phantom.args;
|
||||||
|
} else if (system) {
|
||||||
|
min = 1;
|
||||||
|
result = params = system.args;
|
||||||
|
} else if (argv) {
|
||||||
|
min = 2;
|
||||||
|
result = params = argv;
|
||||||
|
} else if (params) {
|
||||||
|
result = params;
|
||||||
|
}
|
||||||
var last = result[result.length - 1];
|
var last = result[result.length - 1];
|
||||||
result = (result.length > min && !/perf(?:\.js)?$/.test(last))
|
result = (result.length > min && !/perf(?:\.js)?$/.test(last)) ? last : '../lodash.js';
|
||||||
? last
|
|
||||||
: '../lodash.js';
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = require('fs').realpathSync(result);
|
|
||||||
} catch(e) { }
|
|
||||||
|
|
||||||
|
if (!amd) {
|
||||||
|
try {
|
||||||
|
return require('fs').realpathSync(result);
|
||||||
|
} catch(e) { }
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -29,6 +54,7 @@
|
|||||||
var lodash = root.lodash || (root.lodash = (
|
var lodash = root.lodash || (root.lodash = (
|
||||||
lodash = load(filePath) || root._,
|
lodash = load(filePath) || root._,
|
||||||
lodash = lodash._ || lodash,
|
lodash = lodash._ || lodash,
|
||||||
|
(lodash.runInContext ? lodash.runInContext(root) : lodash),
|
||||||
lodash.noConflict()
|
lodash.noConflict()
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -45,6 +71,10 @@
|
|||||||
_._ || _
|
_._ || _
|
||||||
));
|
));
|
||||||
|
|
||||||
|
try {
|
||||||
|
filePath = require.resolve(filePath);
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
/** Used to access the Firebug Lite panel (set by `run`) */
|
/** Used to access the Firebug Lite panel (set by `run`) */
|
||||||
var fbPanel;
|
var fbPanel;
|
||||||
|
|
||||||
@@ -404,24 +434,16 @@
|
|||||||
if (typeof multiArrays != "undefined") {\
|
if (typeof multiArrays != "undefined") {\
|
||||||
var twentyValues = Array(20),\
|
var twentyValues = Array(20),\
|
||||||
twentyValues2 = Array(20),\
|
twentyValues2 = Array(20),\
|
||||||
twentyFiveValues = Array(25),\
|
|
||||||
twentyFiveValues2 = Array(25),\
|
|
||||||
thirtyValues = Array(30),\
|
|
||||||
thirtyValues2 = Array(30),\
|
|
||||||
fortyValues = Array(40),\
|
fortyValues = Array(40),\
|
||||||
fortyValues2 = Array(40),\
|
fortyValues2 = Array(40),\
|
||||||
fiftyValues = Array(50),\
|
fiftyValues = Array(50),\
|
||||||
fiftyValues2 = Array(50),\
|
fiftyValues2 = Array(50),\
|
||||||
seventyFiveValues = Array(75),\
|
hundredValues = Array(100),\
|
||||||
seventyFiveValues2 = Array(75),\
|
hundredValues2 = Array(100),\
|
||||||
oneHundredValues = Array(100),\
|
|
||||||
oneHundredValues2 = Array(100),\
|
|
||||||
twoHundredValues = Array(200),\
|
|
||||||
twoHundredValues2 = Array(200),\
|
|
||||||
lowerChars = "abcdefghijklmnopqrstuvwxyz".split(""),\
|
lowerChars = "abcdefghijklmnopqrstuvwxyz".split(""),\
|
||||||
upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");\
|
upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");\
|
||||||
\
|
\
|
||||||
for (index = 0; index < 200; index++) {\
|
for (index = 0; index < 100; index++) {\
|
||||||
if (index < 15) {\
|
if (index < 15) {\
|
||||||
twentyValues[index] = lowerChars[index];\
|
twentyValues[index] = lowerChars[index];\
|
||||||
twentyValues2[index] = upperChars[index];\
|
twentyValues2[index] = upperChars[index];\
|
||||||
@@ -429,33 +451,17 @@
|
|||||||
if (index < 20) {\
|
if (index < 20) {\
|
||||||
twentyValues[index] =\
|
twentyValues[index] =\
|
||||||
twentyValues2[index] = index;\
|
twentyValues2[index] = index;\
|
||||||
\
|
|
||||||
twentyFiveValues[index] = lowerChars[index];\
|
|
||||||
twentyFiveValues2[index] = upperChars[index];\
|
|
||||||
}\
|
}\
|
||||||
if (index < 25) {\
|
if (index < 25) {\
|
||||||
twentyFiveValues[index] =\
|
|
||||||
twentyFiveValues2[index] = index;\
|
|
||||||
\
|
|
||||||
thirtyValues[index] =\
|
|
||||||
fortyValues[index] =\
|
fortyValues[index] =\
|
||||||
fiftyValues[index] =\
|
fiftyValues[index] =\
|
||||||
seventyFiveValues[index] =\
|
hundredValues[index] = lowerChars[index];\
|
||||||
oneHundredValues[index] =\
|
|
||||||
twoHundredValues[index] = lowerChars[index];\
|
|
||||||
\
|
\
|
||||||
thirtyValues2[index] =\
|
|
||||||
fortyValues2[index] =\
|
fortyValues2[index] =\
|
||||||
fiftyValues2[index] =\
|
fiftyValues2[index] =\
|
||||||
seventyFiveValues2[index] =\
|
hundredValues2[index] = upperChars[index];\
|
||||||
oneHundredValues2[index] =\
|
|
||||||
twoHundredValues2[index] = upperChars[index];\
|
|
||||||
}\
|
}\
|
||||||
else {\
|
else {\
|
||||||
if (index < 30) {\
|
|
||||||
thirtyValues[index] =\
|
|
||||||
thirtyValues2[index] = index;\
|
|
||||||
}\
|
|
||||||
if (index < 40) {\
|
if (index < 40) {\
|
||||||
fortyValues[index] =\
|
fortyValues[index] =\
|
||||||
fortyValues2[index] = index;\
|
fortyValues2[index] = index;\
|
||||||
@@ -464,16 +470,8 @@
|
|||||||
fiftyValues[index] =\
|
fiftyValues[index] =\
|
||||||
fiftyValues2[index] = index;\
|
fiftyValues2[index] = index;\
|
||||||
}\
|
}\
|
||||||
if (index < 75) {\
|
hundredValues[index] =\
|
||||||
seventyFiveValues[index] =\
|
hundredValues2[index] = index;\
|
||||||
seventyFiveValues2[index] = index;\
|
|
||||||
}\
|
|
||||||
if (index < 100) {\
|
|
||||||
oneHundredValues[index] =\
|
|
||||||
oneHundredValues2[index] = index;\
|
|
||||||
}\
|
|
||||||
twoHundredValues[index] =\
|
|
||||||
twoHundredValues2[index] = index;\
|
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
}\
|
}\
|
||||||
@@ -800,25 +798,25 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.difference` iterating 75 elements')
|
Benchmark.Suite('`_.difference` iterating 40 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.difference(seventyFiveValues, seventyFiveValues2)',
|
'fn': 'lodash.difference(twentyValues, twentyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.difference(seventyFiveValues, seventyFiveValues2)',
|
'fn': '_.difference(twentyValues, twentyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.difference` iterating 200 elements')
|
Benchmark.Suite('`_.difference` iterating 100 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.difference(twoHundredValues, twoHundredValues2)',
|
'fn': 'lodash.difference(hundredValues, hundredValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.difference(twoHundredValues, twoHundredValues2)',
|
'fn': '_.difference(hundredValues, hundredValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1137,11 +1135,11 @@
|
|||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.indexOf`')
|
Benchmark.Suite('`_.indexOf`')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.indexOf(twoHundredValues, 199)',
|
'fn': 'lodash.indexOf(hundredValues, 99)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.indexOf(twoHundredValues, 199)',
|
'fn': '_.indexOf(hundredValues, 99)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1159,25 +1157,25 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.intersection` iterating 75 elements')
|
Benchmark.Suite('`_.intersection` iterating 40 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.intersection(seventyFiveValues, seventyFiveValues2)',
|
'fn': 'lodash.intersection(fortyValues, fortyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.intersection(seventyFiveValues, seventyFiveValues2)',
|
'fn': '_.intersection(fortyValues, fortyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.intersection` iterating 200 elements')
|
Benchmark.Suite('`_.intersection` iterating 100 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.intersection(twoHundredValues, twoHundredValues2)',
|
'fn': 'lodash.intersection(hundredValues, hundredValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.intersection(twoHundredValues, twoHundredValues2)',
|
'fn': '_.intersection(hundredValues, hundredValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1883,25 +1881,25 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.union` iterating an array of 75 elements')
|
Benchmark.Suite('`_.union` iterating an array of 40 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.union(twentyFiveValues, fiftyValues2)',
|
'fn': 'lodash.union(twentyValues, twentyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.union(twentyFiveValues, fiftyValues2)',
|
'fn': '_.union(twentyValues, twentyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.union` iterating an array of 200 elements')
|
Benchmark.Suite('`_.union` iterating an array of 100 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.union(oneHundredValues, oneHundredValues2)',
|
'fn': 'lodash.union(fiftyValues, fiftyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.union(oneHundredValues, oneHundredValues2)',
|
'fn': '_.union(fiftyValues, fiftyValues2)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -1933,25 +1931,25 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.uniq` iterating an array of 75 elements')
|
Benchmark.Suite('`_.uniq` iterating an array of 40 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.uniq(twentyFiveValues.concat(fiftyValues2))',
|
'fn': 'lodash.uniq(fortyValues)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.uniq(twentyFiveValues.concat(fiftyValues2))',
|
'fn': '_.uniq(fortyValues)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
suites.push(
|
suites.push(
|
||||||
Benchmark.Suite('`_.uniq` iterating an array of 200 elements')
|
Benchmark.Suite('`_.uniq` iterating an array of 100 elements')
|
||||||
.add(buildName, {
|
.add(buildName, {
|
||||||
'fn': 'lodash.uniq(oneHundredValues.concat(oneHundredValues2))',
|
'fn': 'lodash.uniq(hundredValues)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
.add(otherName, {
|
.add(otherName, {
|
||||||
'fn': '_.uniq(oneHundredValues.concat(oneHundredValues2))',
|
'fn': '_.uniq(hundredValues)',
|
||||||
'teardown': 'function multiArrays(){}'
|
'teardown': 'function multiArrays(){}'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -2028,9 +2026,9 @@
|
|||||||
log(Benchmark.platform);
|
log(Benchmark.platform);
|
||||||
}
|
}
|
||||||
// in the browser, expose `run` to be called later
|
// in the browser, expose `run` to be called later
|
||||||
if (root.document && !root.phantom) {
|
if (document) {
|
||||||
root.run = run;
|
root.run = run;
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
}(typeof global == 'object' && global || this));
|
}.call(this));
|
||||||
|
|||||||
Reference in New Issue
Block a user