mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Add isHostType to perf.js.
Former-commit-id: 36a1818a5272966ac9bd7f2394f2bd466fe6a4d4
This commit is contained in:
83
perf/perf.js
83
perf/perf.js
@@ -48,6 +48,15 @@
|
|||||||
/** Used to access the Firebug Lite panel (set by `run`) */
|
/** Used to access the Firebug Lite panel (set by `run`) */
|
||||||
var fbPanel;
|
var fbPanel;
|
||||||
|
|
||||||
|
/** Used to match path separators */
|
||||||
|
var rePathSeparator = /[\/\\]/;
|
||||||
|
|
||||||
|
/** Used to detect primitive types */
|
||||||
|
var rePrimitive = /^(?:boolean|number|string|undefined)$/;
|
||||||
|
|
||||||
|
/** Used to match RegExp special characters */
|
||||||
|
var reSpecialChars = /[.*+?^=!:${}()|[\]\/\\]/g;
|
||||||
|
|
||||||
/** Used to score performance */
|
/** Used to score performance */
|
||||||
var score = { 'a': 0, 'b': 0 };
|
var score = { 'a': 0, 'b': 0 };
|
||||||
|
|
||||||
@@ -70,7 +79,7 @@
|
|||||||
var otherName = basename(ui.otherPath, '.js');
|
var otherName = basename(ui.otherPath, '.js');
|
||||||
|
|
||||||
/** Detect if in a browser environment */
|
/** Detect if in a browser environment */
|
||||||
var isBrowser = !!(window.document && window.navigator);
|
var isBrowser = isHostType(window, 'document') && isHostType(window, 'navigator');
|
||||||
|
|
||||||
/** Detect Java environment */
|
/** Detect Java environment */
|
||||||
var isJava = !isBrowser && /Java/.test(toString.call(window.java));
|
var isJava = !isBrowser && /Java/.test(toString.call(window.java));
|
||||||
@@ -90,10 +99,10 @@
|
|||||||
* @returns {String} Returns the basename.
|
* @returns {String} Returns the basename.
|
||||||
*/
|
*/
|
||||||
function basename(filePath, extension) {
|
function basename(filePath, extension) {
|
||||||
var result = (filePath || '').split(/[\\/]/).pop();
|
var result = (filePath || '').split(rePathSeparator).pop();
|
||||||
return arguments.length < 2
|
return (arguments.length < 2)
|
||||||
? result
|
? result
|
||||||
: result.replace(RegExp(extension.replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&') + '$'), '');
|
: result.replace(RegExp(extension.replace(reSpecialChars, '\\$&') + '$'), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +118,24 @@
|
|||||||
return isFinite(result) ? result : 0;
|
return isFinite(result) ? result : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Host objects can return type values that are different from their actual
|
||||||
|
* data type. The objects we are concerned with usually return non-primitive
|
||||||
|
* types of "object", "function", or "unknown".
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Mixed} object The owner of the property.
|
||||||
|
* @param {String} property The property to check.
|
||||||
|
* @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`.
|
||||||
|
*/
|
||||||
|
function isHostType(object, property) {
|
||||||
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var type = typeof object[property];
|
||||||
|
return !rePrimitive.test(type) && (type != 'object' || !!object[property]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs text to the console.
|
* Logs text to the console.
|
||||||
*
|
*
|
||||||
@@ -494,17 +521,19 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
// avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo
|
// avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo
|
||||||
!isJava && suites.push(
|
if (!isJava) {
|
||||||
Benchmark.Suite('`_(...).tap(...)`')
|
suites.push(
|
||||||
.add(buildName, {
|
Benchmark.Suite('`_(...).tap(...)`')
|
||||||
'fn': 'lodashChaining.tap(lodash.identity)',
|
.add(buildName, {
|
||||||
'teardown': 'function chaining(){}'
|
'fn': 'lodashChaining.tap(lodash.identity)',
|
||||||
})
|
'teardown': 'function chaining(){}'
|
||||||
.add(otherName, {
|
})
|
||||||
'fn': '_chaining.tap(_.identity)',
|
.add(otherName, {
|
||||||
'teardown': 'function chaining(){}'
|
'fn': '_chaining.tap(_.identity)',
|
||||||
})
|
'teardown': 'function chaining(){}'
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -893,17 +922,19 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
// avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo
|
// avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo
|
||||||
!isJava && suites.push(
|
if (!isJava) {
|
||||||
Benchmark.Suite('`_.find` with `properties`')
|
suites.push(
|
||||||
.add(buildName, {
|
Benchmark.Suite('`_.find` with `properties`')
|
||||||
'fn': 'lodash.find(objects, whereObject)',
|
.add(buildName, {
|
||||||
'teardown': 'function where(){}'
|
'fn': 'lodash.find(objects, whereObject)',
|
||||||
})
|
'teardown': 'function where(){}'
|
||||||
.add(otherName, {
|
})
|
||||||
'fn': '_.findWhere(objects, whereObject)',
|
.add(otherName, {
|
||||||
'teardown': 'function where(){}'
|
'fn': '_.findWhere(objects, whereObject)',
|
||||||
})
|
'teardown': 'function where(){}'
|
||||||
);
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
13
vendor/benchmark.js/benchmark.js
vendored
13
vendor/benchmark.js/benchmark.js
vendored
@@ -30,6 +30,9 @@
|
|||||||
/** Used to assign each benchmark an incrimented id */
|
/** Used to assign each benchmark an incrimented id */
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
|
|
||||||
|
/** Used to detect primitive types */
|
||||||
|
var rePrimitive = /^(?:boolean|number|string|undefined)$/;
|
||||||
|
|
||||||
/** Used to assign default `context` object properties */
|
/** Used to assign default `context` object properties */
|
||||||
var contextProps = [
|
var contextProps = [
|
||||||
'Array', 'Date', 'Function', 'Math', 'Object', 'RegExp', 'String', '_',
|
'Array', 'Date', 'Function', 'Math', 'Object', 'RegExp', 'String', '_',
|
||||||
@@ -613,7 +616,7 @@
|
|||||||
/**
|
/**
|
||||||
* Host objects can return type values that are different from their actual
|
* Host objects can return type values that are different from their actual
|
||||||
* data type. The objects we are concerned with usually return non-primitive
|
* data type. The objects we are concerned with usually return non-primitive
|
||||||
* types of object, function, or unknown.
|
* types of "object", "function", or "unknown".
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Mixed} object The owner of the property.
|
* @param {Mixed} object The owner of the property.
|
||||||
@@ -621,9 +624,11 @@
|
|||||||
* @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`.
|
* @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`.
|
||||||
*/
|
*/
|
||||||
function isHostType(object, property) {
|
function isHostType(object, property) {
|
||||||
var type = object != null ? typeof object[property] : 'number';
|
if (object == null) {
|
||||||
return !/^(?:boolean|number|string|undefined)$/.test(type) &&
|
return false;
|
||||||
(type == 'object' ? !!object[property] : true);
|
}
|
||||||
|
var type = typeof object[property];
|
||||||
|
return !rePrimitive.test(type) && (type != 'object' || !!object[property]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2
vendor/platform.js/platform.js
vendored
2
vendor/platform.js/platform.js
vendored
@@ -20,7 +20,7 @@
|
|||||||
var reOpera = /Opera/;
|
var reOpera = /Opera/;
|
||||||
|
|
||||||
/** Used to resolve a value's internal [[Class]] */
|
/** Used to resolve a value's internal [[Class]] */
|
||||||
var toString = {}.toString;
|
var toString = Object.prototype.toString;
|
||||||
|
|
||||||
/** Detect Java environment */
|
/** Detect Java environment */
|
||||||
var java = /Java/.test(getClassOf(window.java)) && window.java;
|
var java = /Java/.test(getClassOf(window.java)) && window.java;
|
||||||
|
|||||||
Reference in New Issue
Block a user