code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function runSuite(options) {
var me = this;
me.reset();
me.running = true;
options || (options = {});
invoke(me, {
'name': 'run',
'args': options,
'queued': options.queued,
'onStart': function(event) {
me.emit(event);
},
'onCycle': function(event) {
var bench = event.target;
if (bench.error) {
me.emit({ 'type': 'error', 'target': bench });
}
me.emit(event);
event.aborted = me.aborted;
},
'onComplete': function(event) {
me.running = false;
me.emit(event);
}
});
return me;
}
|
Runs the suite.
@name run
@memberOf Benchmark.Suite
@param {Object} [options={}] Options object.
@returns {Object} The suite instance.
@example
// basic usage
suite.run();
// or with options
suite.run({ 'async': true, 'queued': true });
|
runSuite
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function emit(type) {
var listeners,
me = this,
event = Event(type),
events = me.events,
args = (arguments[0] = event, arguments);
event.currentTarget || (event.currentTarget = me);
event.target || (event.target = me);
delete event.result;
if (events && (listeners = hasKey(events, event.type) && events[event.type])) {
forEach(listeners.slice(), function(listener) {
if ((event.result = listener.apply(me, args)) === false) {
event.cancelled = true;
}
return !event.aborted;
});
}
return event.result;
}
|
Executes all registered listeners of the specified event type.
@memberOf Benchmark, Benchmark.Suite
@param {String|Object} type The event type or object.
@returns {Mixed} Returns the return value of the last listener executed.
|
emit
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function listeners(type) {
var me = this,
events = me.events || (me.events = {});
return hasKey(events, type) ? events[type] : (events[type] = []);
}
|
Returns an array of event listeners for a given type that can be manipulated
to add or remove listeners.
@memberOf Benchmark, Benchmark.Suite
@param {String} type The event type.
@returns {Array} The listeners array.
|
listeners
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function off(type, listener) {
var me = this,
events = me.events;
events && each(type ? type.split(' ') : events, function(listeners, type) {
var index;
if (typeof listeners == 'string') {
type = listeners;
listeners = hasKey(events, type) && events[type];
}
if (listeners) {
if (listener) {
index = indexOf(listeners, listener);
if (index > -1) {
listeners.splice(index, 1);
}
} else {
listeners.length = 0;
}
}
});
return me;
}
|
Unregisters a listener for the specified event type(s),
or unregisters all listeners for the specified event type(s),
or unregisters all listeners for all event types.
@memberOf Benchmark, Benchmark.Suite
@param {String} [type] The event type.
@param {Function} [listener] The function to unregister.
@returns {Object} The benchmark instance.
@example
// unregister a listener for an event type
bench.off('cycle', listener);
// unregister a listener for multiple event types
bench.off('start cycle', listener);
// unregister all listeners for an event type
bench.off('cycle');
// unregister all listeners for multiple event types
bench.off('start cycle complete');
// unregister all listeners for all event types
bench.off();
|
off
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function on(type, listener) {
var me = this,
events = me.events || (me.events = {});
forEach(type.split(' '), function(type) {
(hasKey(events, type)
? events[type]
: (events[type] = [])
).push(listener);
});
return me;
}
|
Registers a listener for the specified event type(s).
@memberOf Benchmark, Benchmark.Suite
@param {String} type The event type.
@param {Function} listener The function to register.
@returns {Object} The benchmark instance.
@example
// register a listener for an event type
bench.on('cycle', listener);
// register a listener for multiple event types
bench.on('start cycle', listener);
|
on
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function abort() {
var event,
me = this,
resetting = calledBy.reset;
if (me.running) {
event = Event('abort');
me.emit(event);
if (!event.cancelled || resetting) {
// avoid infinite recursion
calledBy.abort = true;
me.reset();
delete calledBy.abort;
if (support.timeout) {
clearTimeout(me._timerId);
delete me._timerId;
}
if (!resetting) {
me.aborted = true;
me.running = false;
}
}
}
return me;
}
|
Aborts the benchmark without recording times.
@memberOf Benchmark
@returns {Object} The benchmark instance.
|
abort
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function clone(options) {
var me = this,
result = new me.constructor(extend({}, me, options));
// correct the `options` object
result.options = extend({}, me.options, options);
// copy own custom properties
forOwn(me, function(value, key) {
if (!hasKey(result, key)) {
result[key] = deepClone(value);
}
});
return result;
}
|
Creates a new benchmark using the same test and options.
@memberOf Benchmark
@param {Object} options Options object to overwrite cloned options.
@returns {Object} The new benchmark instance.
@example
var bizarro = bench.clone({
'name': 'doppelganger'
});
|
clone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function compare(other) {
var critical,
zStat,
me = this,
sample1 = me.stats.sample,
sample2 = other.stats.sample,
size1 = sample1.length,
size2 = sample2.length,
maxSize = max(size1, size2),
minSize = min(size1, size2),
u1 = getU(sample1, sample2),
u2 = getU(sample2, sample1),
u = min(u1, u2);
function getScore(xA, sampleB) {
return reduce(sampleB, function(total, xB) {
return total + (xB > xA ? 0 : xB < xA ? 1 : 0.5);
}, 0);
}
function getU(sampleA, sampleB) {
return reduce(sampleA, function(total, xA) {
return total + getScore(xA, sampleB);
}, 0);
}
function getZ(u) {
return (u - ((size1 * size2) / 2)) / sqrt((size1 * size2 * (size1 + size2 + 1)) / 12);
}
// exit early if comparing the same benchmark
if (me == other) {
return 0;
}
// reject the null hyphothesis the two samples come from the
// same population (i.e. have the same median) if...
if (size1 + size2 > 30) {
// ...the z-stat is greater than 1.96 or less than -1.96
// http://www.statisticslectures.com/topics/mannwhitneyu/
zStat = getZ(u);
return abs(zStat) > 1.96 ? (zStat > 0 ? -1 : 1) : 0;
}
// ...the U value is less than or equal the critical U value
// http://www.geoib.com/mann-whitney-u-test.html
critical = maxSize < 5 || minSize < 3 ? 0 : uTable[maxSize][minSize - 3];
return u <= critical ? (u == u1 ? 1 : -1) : 0;
}
|
Determines if a benchmark is faster than another.
@memberOf Benchmark
@param {Object} other The benchmark to compare.
@returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate.
|
compare
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getScore(xA, sampleB) {
return reduce(sampleB, function(total, xB) {
return total + (xB > xA ? 0 : xB < xA ? 1 : 0.5);
}, 0);
}
|
Determines if a benchmark is faster than another.
@memberOf Benchmark
@param {Object} other The benchmark to compare.
@returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate.
|
getScore
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getU(sampleA, sampleB) {
return reduce(sampleA, function(total, xA) {
return total + getScore(xA, sampleB);
}, 0);
}
|
Determines if a benchmark is faster than another.
@memberOf Benchmark
@param {Object} other The benchmark to compare.
@returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate.
|
getU
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getZ(u) {
return (u - ((size1 * size2) / 2)) / sqrt((size1 * size2 * (size1 + size2 + 1)) / 12);
}
|
Determines if a benchmark is faster than another.
@memberOf Benchmark
@param {Object} other The benchmark to compare.
@returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate.
|
getZ
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function reset() {
var data,
event,
me = this,
index = 0,
changes = { 'length': 0 },
queue = { 'length': 0 };
if (me.running && !calledBy.abort) {
// no worries, `reset()` is called within `abort()`
calledBy.reset = true;
me.abort();
delete calledBy.reset;
}
else {
// a non-recursive solution to check if properties have changed
// http://www.jslab.dk/articles/non.recursive.preorder.traversal.part4
data = { 'destination': me, 'source': extend({}, me.constructor.prototype, me.options) };
do {
forOwn(data.source, function(value, key) {
var changed,
destination = data.destination,
currValue = destination[key];
if (value && typeof value == 'object') {
if (isClassOf(value, 'Array')) {
// check if an array value has changed to a non-array value
if (!isClassOf(currValue, 'Array')) {
changed = currValue = [];
}
// or has changed its length
if (currValue.length != value.length) {
changed = currValue = currValue.slice(0, value.length);
currValue.length = value.length;
}
}
// check if an object has changed to a non-object value
else if (!currValue || typeof currValue != 'object') {
changed = currValue = {};
}
// register a changed object
if (changed) {
changes[changes.length++] = { 'destination': destination, 'key': key, 'value': currValue };
}
queue[queue.length++] = { 'destination': currValue, 'source': value };
}
// register a changed primitive
else if (value !== currValue && !(value == null || isClassOf(value, 'Function'))) {
changes[changes.length++] = { 'destination': destination, 'key': key, 'value': value };
}
});
}
while ((data = queue[index++]));
// if changed emit the `reset` event and if it isn't cancelled reset the benchmark
if (changes.length && (me.emit(event = Event('reset')), !event.cancelled)) {
forEach(changes, function(data) {
data.destination[data.key] = data.value;
});
}
}
return me;
}
|
Reset properties and abort if running.
@memberOf Benchmark
@returns {Object} The benchmark instance.
|
reset
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function toStringBench() {
var me = this,
error = me.error,
hz = me.hz,
id = me.id,
stats = me.stats,
size = stats.sample.length,
pm = support.java ? '+/-' : '\xb1',
result = me.name || (isNaN(id) ? id : '<Test #' + id + '>');
if (error) {
result += ': ' + join(error);
} else {
result += ' x ' + formatNumber(hz.toFixed(hz < 100 ? 2 : 0)) + ' ops/sec ' + pm +
stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)';
}
return result;
}
|
Displays relevant benchmark information when coerced to a string.
@name toString
@memberOf Benchmark
@returns {String} A string representation of the benchmark instance.
|
toStringBench
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function clock() {
var applet,
options = Benchmark.options,
template = { 'begin': 's$=new n$', 'end': 'r$=(new n$-s$)/1e3', 'uid': uid },
timers = [{ 'ns': timer.ns, 'res': max(0.0015, getRes('ms')), 'unit': 'ms' }];
// lazy define for hi-res timers
clock = function(clone) {
var deferred;
if (clone instanceof Deferred) {
deferred = clone;
clone = deferred.benchmark;
}
var bench = clone._original,
fn = bench.fn,
fnArg = deferred ? getFirstArgument(fn) || 'deferred' : '',
stringable = isStringable(fn);
var source = {
'setup': getSource(bench.setup, preprocess('m$.setup()')),
'fn': getSource(fn, preprocess('m$.fn(' + fnArg + ')')),
'fnArg': fnArg,
'teardown': getSource(bench.teardown, preprocess('m$.teardown()'))
};
var count = bench.count = clone.count,
decompilable = support.decompilation || stringable,
id = bench.id,
isEmpty = !(source.fn || stringable),
name = bench.name || (typeof id == 'number' ? '<Test #' + id + '>' : id),
ns = timer.ns,
result = 0;
// init `minTime` if needed
clone.minTime = bench.minTime || (bench.minTime = bench.options.minTime = options.minTime);
// repair nanosecond timer
// (some Chrome builds erase the `ns` variable after millions of executions)
if (applet) {
try {
ns.nanoTime();
} catch(e) {
// use non-element to avoid issues with libs that augment them
ns = timer.ns = new applet.Packages.nano;
}
}
// Compile in setup/teardown functions and the test loop.
// Create a new compiled test, instead of using the cached `bench.compiled`,
// to avoid potential engine optimizations enabled over the life of the test.
var compiled = bench.compiled = createFunction(preprocess('t$'), interpolate(
preprocess(deferred
? 'var d$=this,#{fnArg}=d$,m$=d$.benchmark._original,f$=m$.fn,su$=m$.setup,td$=m$.teardown;' +
// when `deferred.cycles` is `0` then...
'if(!d$.cycles){' +
// set `deferred.fn`
'd$.fn=function(){var #{fnArg}=d$;if(typeof f$=="function"){try{#{fn}\n}catch(e$){f$(d$)}}else{#{fn}\n}};' +
// set `deferred.teardown`
'd$.teardown=function(){d$.cycles=0;if(typeof td$=="function"){try{#{teardown}\n}catch(e$){td$()}}else{#{teardown}\n}};' +
// execute the benchmark's `setup`
'if(typeof su$=="function"){try{#{setup}\n}catch(e$){su$()}}else{#{setup}\n};' +
// start timer
't$.start(d$);' +
// execute `deferred.fn` and return a dummy object
'}d$.fn();return{}'
: 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count,n$=t$.ns;#{setup}\n#{begin};' +
'while(i$--){#{fn}\n}#{end};#{teardown}\nreturn{elapsed:r$,uid:"#{uid}"}'),
source
));
try {
if (isEmpty) {
// Firefox may remove dead code from Function#toString results
// http://bugzil.la/536085
throw new Error('The test "' + name + '" is empty. This may be the result of dead code removal.');
}
else if (!deferred) {
// pretest to determine if compiled code is exits early, usually by a
// rogue `return` statement, by checking for a return object with the uid
bench.count = 1;
compiled = (compiled.call(bench, timer) || {}).uid == uid && compiled;
bench.count = count;
}
} catch(e) {
compiled = null;
clone.error = e || new Error(String(e));
bench.count = count;
}
// fallback when a test exits early or errors during pretest
if (decompilable && !compiled && !deferred && !isEmpty) {
compiled = createFunction(preprocess('t$'), interpolate(
preprocess(
(clone.error && !stringable
? 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count'
: 'function f$(){#{fn}\n}var r$,s$,m$=this,i$=m$.count'
) +
',n$=t$.ns;#{setup}\n#{begin};m$.f$=f$;while(i$--){m$.f$()}#{end};' +
'delete m$.f$;#{teardown}\nreturn{elapsed:r$}'
),
source
));
try {
// pretest one more time to check for errors
bench.count = 1;
compiled.call(bench, timer);
bench.compiled = compiled;
bench.count = count;
delete clone.error;
}
catch(e) {
bench.count = count;
if (clone.error) {
compiled = null;
} else {
bench.compiled = compiled;
clone.error = e || new Error(String(e));
}
}
}
// assign `compiled` to `clone` before calling in case a deferred benchmark
// immediately calls `deferred.resolve()`
clone.compiled = compiled;
// if no errors run the full test loop
if (!clone.error) {
result = compiled.call(deferred || bench, timer).elapsed;
}
return result;
};
/*------------------------------------------------------------------------*/
/**
* Gets the current timer's minimum resolution (secs).
*/
function getRes(unit) {
var measured,
begin,
count = 30,
divisor = 1e3,
ns = timer.ns,
sample = [];
// get average smallest measurable time
while (count--) {
if (unit == 'us') {
divisor = 1e6;
if (ns.stop) {
ns.start();
while (!(measured = ns.microseconds())) { }
} else if (ns[perfName]) {
divisor = 1e3;
measured = Function('n', 'var r,s=n.' + perfName + '();while(!(r=n.' + perfName + '()-s)){};return r')(ns);
} else {
begin = ns();
while (!(measured = ns() - begin)) { }
}
}
else if (unit == 'ns') {
divisor = 1e9;
if (ns.nanoTime) {
begin = ns.nanoTime();
while (!(measured = ns.nanoTime() - begin)) { }
} else {
begin = (begin = ns())[0] + (begin[1] / divisor);
while (!(measured = ((measured = ns())[0] + (measured[1] / divisor)) - begin)) { }
divisor = 1;
}
}
else {
begin = new ns;
while (!(measured = new ns - begin)) { }
}
// check for broken timers (nanoTime may have issues)
// http://alivebutsleepy.srnet.cz/unreliable-system-nanotime/
if (measured > 0) {
sample.push(measured);
} else {
sample.push(Infinity);
break;
}
}
// convert to seconds
return getMean(sample) / divisor;
}
/**
* Replaces all occurrences of `$` with a unique number and
* template tokens with content.
*/
function preprocess(code) {
return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid));
}
/*------------------------------------------------------------------------*/
// detect nanosecond support from a Java applet
each(doc && doc.applets || [], function(element) {
return !(timer.ns = applet = 'nanoTime' in element && element);
});
// check type in case Safari returns an object instead of a number
try {
if (typeof timer.ns.nanoTime() == 'number') {
timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
}
} catch(e) { }
// detect Chrome's microsecond timer:
// enable benchmarking via the --enable-benchmarking command
// line switch in at least Chrome 7 to use chrome.Interval
try {
if ((timer.ns = new (window.chrome || window.chromium).Interval)) {
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
}
} catch(e) { }
// detect `performance.now` microsecond resolution timer
if ((timer.ns = perfName && perfObject)) {
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
}
// detect Node's nanosecond resolution timer available in Node >= 0.8
if (processObject && typeof (timer.ns = processObject.hrtime) == 'function') {
timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' });
}
// detect Wade Simmons' Node microtime module
if (microtimeObject && typeof (timer.ns = microtimeObject.now) == 'function') {
timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' });
}
// pick timer with highest resolution
timer = reduce(timers, function(timer, other) {
return other.res < timer.res ? other : timer;
});
// remove unused applet
if (timer.unit != 'ns' && applet) {
applet = destroyElement(applet);
}
// error if there are no working timers
if (timer.res == Infinity) {
throw new Error('Benchmark.js was unable to find a working timer.');
}
// use API of chosen timer
if (timer.unit == 'ns') {
if (timer.ns.nanoTime) {
extend(template, {
'begin': 's$=n$.nanoTime()',
'end': 'r$=(n$.nanoTime()-s$)/1e9'
});
} else {
extend(template, {
'begin': 's$=n$()',
'end': 'r$=n$(s$);r$=r$[0]+(r$[1]/1e9)'
});
}
}
else if (timer.unit == 'us') {
if (timer.ns.stop) {
extend(template, {
'begin': 's$=n$.start()',
'end': 'r$=n$.microseconds()/1e6'
});
} else if (perfName) {
extend(template, {
'begin': 's$=n$.' + perfName + '()',
'end': 'r$=(n$.' + perfName + '()-s$)/1e3'
});
} else {
extend(template, {
'begin': 's$=n$()',
'end': 'r$=(n$()-s$)/1e6'
});
}
}
// define `timer` methods
timer.start = createFunction(preprocess('o$'),
preprocess('var n$=this.ns,#{begin};o$.elapsed=0;o$.timeStamp=s$'));
timer.stop = createFunction(preprocess('o$'),
preprocess('var n$=this.ns,s$=o$.timeStamp,#{end};o$.elapsed=r$'));
// resolve time span required to achieve a percent uncertainty of at most 1%
// http://spiff.rit.edu/classes/phys273/uncert/uncert.html
options.minTime || (options.minTime = max(timer.res / 2 / 0.01, 0.05));
return clock.apply(null, arguments);
}
|
Clocks the time taken to execute a test per cycle (secs).
@private
@param {Object} bench The benchmark instance.
@returns {Number} The time taken.
|
clock
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getRes(unit) {
var measured,
begin,
count = 30,
divisor = 1e3,
ns = timer.ns,
sample = [];
// get average smallest measurable time
while (count--) {
if (unit == 'us') {
divisor = 1e6;
if (ns.stop) {
ns.start();
while (!(measured = ns.microseconds())) { }
} else if (ns[perfName]) {
divisor = 1e3;
measured = Function('n', 'var r,s=n.' + perfName + '();while(!(r=n.' + perfName + '()-s)){};return r')(ns);
} else {
begin = ns();
while (!(measured = ns() - begin)) { }
}
}
else if (unit == 'ns') {
divisor = 1e9;
if (ns.nanoTime) {
begin = ns.nanoTime();
while (!(measured = ns.nanoTime() - begin)) { }
} else {
begin = (begin = ns())[0] + (begin[1] / divisor);
while (!(measured = ((measured = ns())[0] + (measured[1] / divisor)) - begin)) { }
divisor = 1;
}
}
else {
begin = new ns;
while (!(measured = new ns - begin)) { }
}
// check for broken timers (nanoTime may have issues)
// http://alivebutsleepy.srnet.cz/unreliable-system-nanotime/
if (measured > 0) {
sample.push(measured);
} else {
sample.push(Infinity);
break;
}
}
// convert to seconds
return getMean(sample) / divisor;
}
|
Gets the current timer's minimum resolution (secs).
|
getRes
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function preprocess(code) {
return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid));
}
|
Replaces all occurrences of `$` with a unique number and
template tokens with content.
|
preprocess
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function compute(bench, options) {
options || (options = {});
var async = options.async,
elapsed = 0,
initCount = bench.initCount,
minSamples = bench.minSamples,
queue = [],
sample = bench.stats.sample;
/**
* Adds a clone to the queue.
*/
function enqueue() {
queue.push(bench.clone({
'_original': bench,
'events': {
'abort': [update],
'cycle': [update],
'error': [update],
'start': [update]
}
}));
}
/**
* Updates the clone/original benchmarks to keep their data in sync.
*/
function update(event) {
var clone = this,
type = event.type;
if (bench.running) {
if (type == 'start') {
// Note: `clone.minTime` prop is inited in `clock()`
clone.count = bench.initCount;
}
else {
if (type == 'error') {
bench.error = clone.error;
}
if (type == 'abort') {
bench.abort();
bench.emit('cycle');
} else {
event.currentTarget = event.target = bench;
bench.emit(event);
}
}
} else if (bench.aborted) {
// clear abort listeners to avoid triggering bench's abort/cycle again
clone.events.abort.length = 0;
clone.abort();
}
}
/**
* Determines if more clones should be queued or if cycling should stop.
*/
function evaluate(event) {
var critical,
df,
mean,
moe,
rme,
sd,
sem,
variance,
clone = event.target,
done = bench.aborted,
now = +new Date,
size = sample.push(clone.times.period),
maxedOut = size >= minSamples && (elapsed += now - clone.times.timeStamp) / 1e3 > bench.maxTime,
times = bench.times,
varOf = function(sum, x) { return sum + pow(x - mean, 2); };
// exit early for aborted or unclockable tests
if (done || clone.hz == Infinity) {
maxedOut = !(size = sample.length = queue.length = 0);
}
if (!done) {
// sample mean (estimate of the population mean)
mean = getMean(sample);
// sample variance (estimate of the population variance)
variance = reduce(sample, varOf, 0) / (size - 1) || 0;
// sample standard deviation (estimate of the population standard deviation)
sd = sqrt(variance);
// standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
sem = sd / sqrt(size);
// degrees of freedom
df = size - 1;
// critical value
critical = tTable[Math.round(df) || 1] || tTable.infinity;
// margin of error
moe = sem * critical;
// relative margin of error
rme = (moe / mean) * 100 || 0;
extend(bench.stats, {
'deviation': sd,
'mean': mean,
'moe': moe,
'rme': rme,
'sem': sem,
'variance': variance
});
// Abort the cycle loop when the minimum sample size has been collected
// and the elapsed time exceeds the maximum time allowed per benchmark.
// We don't count cycle delays toward the max time because delays may be
// increased by browsers that clamp timeouts for inactive tabs.
// https://developer.mozilla.org/en/window.setTimeout#Inactive_tabs
if (maxedOut) {
// reset the `initCount` in case the benchmark is rerun
bench.initCount = initCount;
bench.running = false;
done = true;
times.elapsed = (now - times.timeStamp) / 1e3;
}
if (bench.hz != Infinity) {
bench.hz = 1 / mean;
times.cycle = mean * bench.count;
times.period = mean;
}
}
// if time permits, increase sample size to reduce the margin of error
if (queue.length < 2 && !maxedOut) {
enqueue();
}
// abort the invoke cycle when done
event.aborted = done;
}
// init queue and begin
enqueue();
invoke(queue, {
'name': 'run',
'args': { 'async': async },
'queued': true,
'onCycle': evaluate,
'onComplete': function() { bench.emit('complete'); }
});
}
|
Computes stats on benchmark results.
@private
@param {Object} bench The benchmark instance.
@param {Object} options The options object.
|
compute
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function update(event) {
var clone = this,
type = event.type;
if (bench.running) {
if (type == 'start') {
// Note: `clone.minTime` prop is inited in `clock()`
clone.count = bench.initCount;
}
else {
if (type == 'error') {
bench.error = clone.error;
}
if (type == 'abort') {
bench.abort();
bench.emit('cycle');
} else {
event.currentTarget = event.target = bench;
bench.emit(event);
}
}
} else if (bench.aborted) {
// clear abort listeners to avoid triggering bench's abort/cycle again
clone.events.abort.length = 0;
clone.abort();
}
}
|
Updates the clone/original benchmarks to keep their data in sync.
|
update
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function evaluate(event) {
var critical,
df,
mean,
moe,
rme,
sd,
sem,
variance,
clone = event.target,
done = bench.aborted,
now = +new Date,
size = sample.push(clone.times.period),
maxedOut = size >= minSamples && (elapsed += now - clone.times.timeStamp) / 1e3 > bench.maxTime,
times = bench.times,
varOf = function(sum, x) { return sum + pow(x - mean, 2); };
// exit early for aborted or unclockable tests
if (done || clone.hz == Infinity) {
maxedOut = !(size = sample.length = queue.length = 0);
}
if (!done) {
// sample mean (estimate of the population mean)
mean = getMean(sample);
// sample variance (estimate of the population variance)
variance = reduce(sample, varOf, 0) / (size - 1) || 0;
// sample standard deviation (estimate of the population standard deviation)
sd = sqrt(variance);
// standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
sem = sd / sqrt(size);
// degrees of freedom
df = size - 1;
// critical value
critical = tTable[Math.round(df) || 1] || tTable.infinity;
// margin of error
moe = sem * critical;
// relative margin of error
rme = (moe / mean) * 100 || 0;
extend(bench.stats, {
'deviation': sd,
'mean': mean,
'moe': moe,
'rme': rme,
'sem': sem,
'variance': variance
});
// Abort the cycle loop when the minimum sample size has been collected
// and the elapsed time exceeds the maximum time allowed per benchmark.
// We don't count cycle delays toward the max time because delays may be
// increased by browsers that clamp timeouts for inactive tabs.
// https://developer.mozilla.org/en/window.setTimeout#Inactive_tabs
if (maxedOut) {
// reset the `initCount` in case the benchmark is rerun
bench.initCount = initCount;
bench.running = false;
done = true;
times.elapsed = (now - times.timeStamp) / 1e3;
}
if (bench.hz != Infinity) {
bench.hz = 1 / mean;
times.cycle = mean * bench.count;
times.period = mean;
}
}
// if time permits, increase sample size to reduce the margin of error
if (queue.length < 2 && !maxedOut) {
enqueue();
}
// abort the invoke cycle when done
event.aborted = done;
}
|
Determines if more clones should be queued or if cycling should stop.
|
evaluate
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function cycle(clone, options) {
options || (options = {});
var deferred;
if (clone instanceof Deferred) {
deferred = clone;
clone = clone.benchmark;
}
var clocked,
cycles,
divisor,
event,
minTime,
period,
async = options.async,
bench = clone._original,
count = clone.count,
times = clone.times;
// continue, if not aborted between cycles
if (clone.running) {
// `minTime` is set to `Benchmark.options.minTime` in `clock()`
cycles = ++clone.cycles;
clocked = deferred ? deferred.elapsed : clock(clone);
minTime = clone.minTime;
if (cycles > bench.cycles) {
bench.cycles = cycles;
}
if (clone.error) {
event = Event('error');
event.message = clone.error;
clone.emit(event);
if (!event.cancelled) {
clone.abort();
}
}
}
// continue, if not errored
if (clone.running) {
// time taken to complete last test cycle
bench.times.cycle = times.cycle = clocked;
// seconds per operation
period = bench.times.period = times.period = clocked / count;
// ops per second
bench.hz = clone.hz = 1 / period;
// avoid working our way up to this next time
bench.initCount = clone.initCount = count;
// do we need to do another cycle?
clone.running = clocked < minTime;
if (clone.running) {
// tests may clock at `0` when `initCount` is a small number,
// to avoid that we set its count to something a bit higher
if (!clocked && (divisor = divisors[clone.cycles]) != null) {
count = floor(4e6 / divisor);
}
// calculate how many more iterations it will take to achive the `minTime`
if (count <= clone.count) {
count += Math.ceil((minTime - clocked) / period);
}
clone.running = count != Infinity;
}
}
// should we exit early?
event = Event('cycle');
clone.emit(event);
if (event.aborted) {
clone.abort();
}
// figure out what to do next
if (clone.running) {
// start a new cycle
clone.count = count;
if (deferred) {
clone.compiled.call(deferred, timer);
} else if (async) {
delay(clone, function() { cycle(clone, options); });
} else {
cycle(clone);
}
}
else {
// fix TraceMonkey bug associated with clock fallbacks
// http://bugzil.la/509069
if (support.browser) {
runScript(uid + '=1;delete ' + uid);
}
// done
clone.emit('complete');
}
}
|
Cycles a benchmark until a run `count` can be established.
@private
@param {Object} clone The cloned benchmark instance.
@param {Object} options The options object.
|
cycle
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function run(options) {
var me = this,
event = Event('start');
// set `running` to `false` so `reset()` won't call `abort()`
me.running = false;
me.reset();
me.running = true;
me.count = me.initCount;
me.times.timeStamp = +new Date;
me.emit(event);
if (!event.cancelled) {
options = { 'async': ((options = options && options.async) == null ? me.async : options) && support.timeout };
// for clones created within `compute()`
if (me._original) {
if (me.defer) {
Deferred(me);
} else {
cycle(me, options);
}
}
// for original benchmarks
else {
compute(me, options);
}
}
return me;
}
|
Runs the benchmark.
@memberOf Benchmark
@param {Object} [options={}] Options object.
@returns {Object} The benchmark instance.
@example
// basic usage
bench.run();
// or with options
bench.run({ 'async': true });
|
run
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayEach(array, iteratee) {
var index = -1,
length = array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
}
|
A specialized version of `_.forEach` for arrays without support for
callback shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns `array`.
|
arrayEach
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayEachRight(array, iteratee) {
var length = array.length;
while (length--) {
if (iteratee(array[length], length, array) === false) {
break;
}
}
return array;
}
|
A specialized version of `_.forEachRight` for arrays without support for
callback shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns `array`.
|
arrayEachRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayEvery(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (!predicate(array[index], index, array)) {
return false;
}
}
return true;
}
|
A specialized version of `_.every` for arrays without support for callback
shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {Array} Returns `true` if all elements pass the predicate check,
else `false`
|
arrayEvery
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayFilter(array, predicate) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[++resIndex] = value;
}
}
return result;
}
|
A specialized version of `_.filter` for arrays without support for callback
shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {Array} Returns the new filtered array.
|
arrayFilter
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayMap(array, iteratee) {
var index = -1,
length = array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
|
A specialized version of `_.map` for arrays without support for callback
shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns the new mapped array.
|
arrayMap
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayReduce(array, iteratee, accumulator, initFromArray) {
var index = -1,
length = array.length;
if (initFromArray && length) {
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
}
|
A specialized version of `_.reduce` for arrays without support for callback
shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {*} [accumulator] The initial value.
@param {boolean} [initFromArray=false] Specify using the first element of
`array` as the initial value.
@returns {*} Returns the accumulated value.
|
arrayReduce
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
var length = array.length;
if (initFromArray && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
}
|
A specialized version of `_.reduceRight` for arrays without support for
callback shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {*} [accumulator] The initial value.
@param {boolean} [initFromArray=false] Specify using the last element of
`array` as the initial value.
@returns {*} Returns the accumulated value.
|
arrayReduceRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arraySome(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
|
A specialized version of `_.some` for arrays without support for callback
shorthands or `this` binding.
@private
@param {Array} array The array to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {boolean} Returns `true` if any element passes the predicate check,
else `false`.
|
arraySome
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseCompareAscending(value, other) {
if (value !== other) {
var valIsReflexive = value === value,
othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
return 1;
}
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
return -1;
}
}
return 0;
}
|
The base implementation of `compareAscending` which compares values and
sorts them in ascending order without guaranteeing a stable sort.
@private
@param {*} value The value to compare to `other`.
@param {*} other The value to compare to `value`.
@returns {number} Returns the sort order indicator for `value`.
|
baseCompareAscending
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseIndexOf(array, value, fromIndex) {
if (value !== value) {
return indexOfNaN(array, fromIndex);
}
var index = (fromIndex || 0) - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
|
The base implementation of `_.indexOf` without support for `fromIndex`
bounds checks and binary searches.
@private
@param {Array} array The array to search.
@param {*} value The value to search for.
@param {number} [fromIndex=0] The index to search from.
@returns {number} Returns the index of the matched value, else `-1`.
|
baseIndexOf
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseSlice(array) {
var index = -1,
length = array ? array.length : 0,
result = Array(length);
while (++index < length) {
result[index] = array[index];
}
return result;
}
|
The base implementation of `_.slice` without support for `start` and `end`
arguments.
@private
@param {Array} array The array to slice.
@returns {Array} Returns the slice of `array`.
|
baseSlice
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function charAtCallback(string) {
return string.charCodeAt(0);
}
|
Used by `_.max` and `_.min` as the default callback for string values.
@private
@param {string} string The string to inspect.
@returns {number} Returns the code unit of the first character of the string.
|
charAtCallback
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function charsLeftIndex(string, chars) {
var index = -1,
length = string.length;
while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
return index;
}
|
Used by `_.trim` and `_.trimLeft` to get the index of the first character
of `string` that is not found in `chars`.
@private
@param {string} string The string to inspect.
@param {string} chars The characters to find.
@returns {number} Returns the index of the first character not found in `chars`.
|
charsLeftIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function charsRightIndex(string, chars) {
var index = string.length;
while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
return index;
}
|
Used by `_.trim` and `_.trimRight` to get the index of the last character
of `string` that is not found in `chars`.
@private
@param {string} string The string to inspect.
@param {string} chars The characters to find.
@returns {number} Returns the index of the last character not found in `chars`.
|
charsRightIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function compareAscending(object, other) {
return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
}
|
Used by `_.sortBy` to compare transformed elements of `collection` and stable
sort them in ascending order.
@private
@param {Object} object The object to compare to `other`.
@param {Object} other The object to compare to `object`.
@returns {number} Returns the sort order indicator for `object`.
|
compareAscending
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function compareMultipleAscending(object, other) {
var index = -1,
objCriteria = object.criteria,
othCriteria = other.criteria,
length = objCriteria.length;
while (++index < length) {
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
if (result) {
return result;
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provide the same value
// for `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
//
// This also ensures a stable sort in V8 and other engines.
// See https://code.google.com/p/v8/issues/detail?id=90.
return object.index - other.index;
}
|
Used by `_.sortBy` to compare multiple properties of each element in a
collection and stable sort them in ascending order.
@private
@param {Object} object The object to compare to `other`.
@param {Object} other The object to compare to `object`.
@returns {number} Returns the sort order indicator for `object`.
|
compareMultipleAscending
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function deburrLetter(letter) {
return deburredLetters[letter];
}
|
Used by `_.deburr` to convert latin-1 to basic latin letters.
@private
@param {string} letter The matched letter to deburr.
@returns {string} Returns the deburred letter.
|
deburrLetter
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function escapeHtmlChar(chr) {
return htmlEscapes[chr];
}
|
Used by `_.escape` to convert characters to HTML entities.
@private
@param {string} chr The matched character to escape.
@returns {string} Returns the escaped character.
|
escapeHtmlChar
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function escapeStringChar(chr) {
return '\\' + stringEscapes[chr];
}
|
Used by `_.template` to escape characters for inclusion in compiled
string literals.
@private
@param {string} chr The matched character to escape.
@returns {string} Returns the escaped character.
|
escapeStringChar
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length,
index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1);
while ((fromRight ? index-- : ++index < length)) {
var other = array[index];
if (other !== other) {
return index;
}
}
return -1;
}
|
Gets the index at which the first occurrence of `NaN` is found in `array`.
If `fromRight` is provided elements of `array` are iterated from right to left.
@private
@param {Array} array The array to search.
@param {number} [fromIndex] The index to search from.
@param {boolean} [fromRight=false] Specify iterating from right to left.
@returns {number} Returns the index of the matched `NaN`, else `-1`.
|
indexOfNaN
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isIndex(value, length) {
value = +value;
return value > -1 && value % 1 == 0 && (length == null || value < length);
}
|
Checks if `value` is valid array-like index.
@private
@param {*} value The value to check.
@param {number} [length] The upper bound of a valid index.
@returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
isIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isWhitespace(charCode) {
return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
(charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
}
|
Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
character code is whitespace.
@private
@param {number} charCode The character code to inspect.
@returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
|
isWhitespace
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function replaceHolders(array, placeholder) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
if (array[index] === placeholder) {
array[index] = PLACEHOLDER;
result[++resIndex] = index;
}
}
return result;
}
|
Replaces all `placeholder` elements in `array` with an internal placeholder
and returns an array of their indexes.
@private
@param {Array} array The array to modify.
@param {*} placeholder The placeholder to replace.
@returns {Array} Returns the new array of placeholder indexes.
|
replaceHolders
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function sortedUniq(array, iteratee) {
var seen,
index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (!index || seen !== computed) {
seen = computed;
result[++resIndex] = value;
}
}
return result;
}
|
An implementation of `_.uniq` optimized for sorted arrays without support
for callback shorthands and `this` binding.
@private
@param {Array} array The array to inspect.
@param {Function} [iteratee] The function invoked per iteration.
@returns {Array} Returns the new duplicate-value-free array.
|
sortedUniq
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function trimmedLeftIndex(string) {
var index = -1,
length = string.length;
while (++index < length && isWhitespace(string.charCodeAt(index))) {}
return index;
}
|
Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
character of `string`.
@private
@param {string} string The string to inspect.
@returns {number} Returns the index of the first non-whitespace character.
|
trimmedLeftIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function trimmedRightIndex(string) {
var index = string.length;
while (index-- && isWhitespace(string.charCodeAt(index))) {}
return index;
}
|
Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
character of `string`.
@private
@param {string} string The string to inspect.
@returns {number} Returns the index of the last non-whitespace character.
|
trimmedRightIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function unescapeHtmlChar(chr) {
return htmlUnescapes[chr];
}
|
Used by `_.unescape` to convert HTML entities to characters.
@private
@param {string} chr The matched character to unescape.
@returns {string} Returns the unescaped character.
|
unescapeHtmlChar
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function LodashWrapper(value, chainAll, queue) {
this.__chain__ = !!chainAll;
this.__queue__ = queue || [];
this.__wrapped__ = value;
}
|
The base constructor for creating `lodash` wrapper objects.
@private
@param {*} value The value to wrap.
@param {boolean} [chainAll=false] Enable chaining for all wrapper methods.
@param {Array} [queue=[]] Actions to peform to resolve the unwrapped value.
|
LodashWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function LazyWrapper(value) {
this.dir = 1;
this.dropCount = 0;
this.filtered = false;
this.iteratees = null;
this.takeCount = POSITIVE_INFINITY;
this.views = null;
this.wrapped = value;
}
|
Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
@private
@param {*} value The value to wrap.
|
LazyWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function lazyClone() {
var iteratees = this.iteratees,
views = this.views,
result = new LazyWrapper(this.wrapped);
result.dir = this.dir;
result.dropCount = this.dropCount;
result.filtered = this.filtered;
result.iteratees = iteratees ? baseSlice(iteratees) : null;
result.takeCount = this.takeCount;
result.views = views ? baseSlice(views) : null;
return result;
}
|
Creates a clone of the lazy wrapper object.
@private
@name clone
@memberOf LazyWrapper
@returns {Object} Returns the cloned `LazyWrapper` object.
|
lazyClone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function lazyReverse() {
var filtered = this.filtered,
result = filtered ? new LazyWrapper(this) : this.clone();
result.dir = this.dir * -1;
result.filtered = filtered;
return result;
}
|
Reverses the direction of lazy iteration.
@private
@name reverse
@memberOf LazyWrapper
@returns {Object} Returns the new reversed `LazyWrapper` object.
|
lazyReverse
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function lazyValue() {
var array = this.wrapped.value(),
dir = this.dir,
isRight = dir < 0,
length = array.length,
view = getView(0, length, this.views),
start = view.start,
end = view.end,
dropCount = this.dropCount,
takeCount = nativeMin(end - start, this.takeCount - dropCount),
index = isRight ? end : start - 1,
iteratees = this.iteratees,
iterLength = iteratees ? iteratees.length : 0,
resIndex = 0,
result = [];
outer:
while (length-- && resIndex < takeCount) {
index += dir;
var iterIndex = -1,
value = array[index];
while (++iterIndex < iterLength) {
var data = iteratees[iterIndex],
iteratee = data.iteratee,
computed = iteratee(value, index, array),
type = data.type;
if (type == LAZY_MAP_FLAG) {
value = computed;
} else if (!computed) {
if (type == LAZY_FILTER_FLAG) {
continue outer;
} else {
break outer;
}
}
}
if (dropCount) {
dropCount--;
} else {
result[resIndex++] = value;
}
}
return isRight ? result.reverse() : result;
}
|
Extracts the unwrapped value from its lazy wrapper.
@private
@name value
@memberOf LazyWrapper
@returns {*} Returns the unwrapped value.
|
lazyValue
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function MapCache() {
this.__data__ = {};
}
|
Creates a cache object to store key/value pairs.
@private
@static
@name Cache
@memberOf _.memoize
|
MapCache
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function mapGet(key) {
return this.__data__[key];
}
|
Gets the cached value for `key`.
@private
@name get
@memberOf _.memoize.Cache
@param {string} key The key of the value to retrieve.
@returns {*} Returns the cached value.
|
mapGet
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function mapHas(key) {
return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
}
|
Checks if a cached value for `key` exists.
@private
@name has
@memberOf _.memoize.Cache
@param {string} key The name of the entry to check.
@returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
mapHas
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function mapSet(key, value) {
if (key != '__proto__') {
this.__data__[key] = value;
}
return this;
}
|
Adds `value` to `key` of the cache.
@private
@name set
@memberOf _.memoize.Cache
@param {string} key The key of the value to cache.
@param {*} value The value to cache.
@returns {Object} Returns the cache object.
|
mapSet
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function SetCache(values) {
var length = values ? values.length : 0;
this.data = { 'number': {}, 'set': new Set };
while (length--) {
this.push(values[length]);
}
}
|
Creates a cache object to store unique values.
@private
@param {Array} [values] The values to cache.
|
SetCache
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function cacheIndexOf(cache, value) {
var type = typeof value,
data = cache.data,
result = type == 'number' ? data[type][value] : data.set.has(value);
return result ? 0 : -1;
}
|
Checks if `value` is in `cache` mimicking the return signature of
`_.indexOf` by returning `0` if the value is found, else `-1`.
@private
@param {Object} cache The cache to search.
@param {*} value The value to search for.
@returns {number} Returns `0` if `value` is found, else `-1`.
|
cacheIndexOf
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function cachePush(value) {
var data = this.data,
type = typeof value;
if (type == 'number') {
data[type][value] = true;
} else {
data.set.add(value);
}
}
|
Adds `value` to the cache.
@private
@name push
@memberOf SetCache
@param {*} value The value to cache.
|
cachePush
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayMax(array) {
var index = -1,
length = array.length,
result = NEGATIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value > result) {
result = value;
}
}
return result;
}
|
A specialized version of `_.max` for arrays without support for iteratees.
@private
@param {Array} array The array to iterate over.
@returns {*} Returns the maximum value.
|
arrayMax
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function arrayMin(array) {
var index = -1,
length = array.length,
result = POSITIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value < result) {
result = value;
}
}
return result;
}
|
A specialized version of `_.min` for arrays without support for iteratees.
@private
@param {Array} array The array to iterate over.
@returns {*} Returns the minimum value.
|
arrayMin
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
}
|
Used by `_.defaults` to customize its `_.assign` use.
@private
@param {*} objectValue The destination object property value.
@param {*} sourceValue The source object property value.
@returns {*} Returns the value to assign to the destination object.
|
assignDefaults
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
? sourceValue
: objectValue;
}
|
Used by `_.template` to customize its `_.assign` use.
**Note:** This method is like `assignDefaults` except that it ignores
inherited property values when checking if a property is `undefined`.
@private
@param {*} objectValue The destination object property value.
@param {*} sourceValue The source object property value.
@param {string} key The key associated with the object and source values.
@param {Object} object The destination object.
@returns {*} Returns the value to assign to the destination object.
|
assignOwnDefaults
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseAssign(object, source, customizer) {
var index = -1,
props = keys(source),
length = props.length;
while (++index < length) {
var key = props[index];
object[key] = customizer
? customizer(object[key], source[key], key, object, source)
: source[key];
}
return object;
}
|
The base implementation of `_.assign` without support for argument juggling,
multiple sources, and `this` binding.
@private
@param {Object} object The destination object.
@param {Object} source The source object.
@param {Function} [customizer] The function to customize assigning values.
@returns {Object} Returns the destination object.
|
baseAssign
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseAt(collection, props) {
var index = -1,
length = collection ? collection.length : 0,
isArr = isLength(length),
propsLength = props.length,
result = Array(propsLength);
while(++index < propsLength) {
var key = props[index];
if (isArr) {
key = parseFloat(key);
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = collection[key];
}
}
return result;
}
|
The base implementation of `_.at` without support for strings and individual
key arguments.
@private
@param {Array|Object} collection The collection to iterate over.
@param {number[]|string[]} [props] The property names or indexes of elements to pick.
@returns {Array} Returns the new array of picked elements.
|
baseAt
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseBindAll(object, methodNames) {
var index = -1,
length = methodNames.length;
while (++index < length) {
var key = methodNames[index];
object[key] = createWrapper(object[key], BIND_FLAG, object);
}
return object;
}
|
The base implementation of `_.bindAll` without support for individual
method name arguments.
@private
@param {Object} object The object to bind and assign the bound methods to.
@param {string[]} methodNames The object method names to bind.
@returns {Object} Returns `object`.
|
baseBindAll
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
if (typeof thisArg == 'undefined') {
return func;
}
var data = getData(func);
if (typeof data == 'undefined') {
var support = lodash.support;
if (support.funcNames) {
data = !func.name;
}
data = data || !support.funcDecomp;
if (!data) {
var source = fnToString.call(func);
if (!support.funcNames) {
data = !reFuncName.test(source);
}
if (!data) {
// checks if `func` references the `this` keyword and stores the result
data = reThis.test(source) || isNative(func);
baseSetData(func, data);
}
}
}
// exit early if there are no `this` references or `func` is bound
if (data === false || (data !== true && data[1] & BIND_FLAG)) {
return func;
}
switch (argCount) {
case 1: return function(value) {
return func.call(thisArg, value);
};
case 3: return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
case 4: return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
case 5: return function(value, other, key, object, source) {
return func.call(thisArg, value, other, key, object, source);
};
}
return function() {
return func.apply(thisArg, arguments);
};
}
if (func == null) {
return identity;
}
// handle "_.pluck" and "_.where" style callback shorthands
return type == 'object' ? matches(func) : property(func);
}
|
The base implementation of `_.callback` without support for creating
"_.pluck" and "_.where" style callbacks.
@private
@param {*} [func=_.identity] The value to convert to a callback.
@param {*} [thisArg] The `this` binding of the created callback.
@param {number} [argCount] The number of arguments the callback accepts.
@returns {Function} Returns the new function.
|
baseCallback
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
var result;
if (customizer) {
result = object ? customizer(value, key, object) : customizer(value);
}
if (typeof result != 'undefined') {
return result;
}
var isArr = isArray(value);
result = value;
if (isArr) {
result = initArrayClone(value, isDeep);
} else if (isObject(value)) {
result = initObjectClone(value, isDeep);
if (result === null) {
isDeep = false;
result = {};
} else if (isDeep) {
isDeep = toString.call(result) == objectClass;
}
}
if (!isDeep || result === value) {
return result;
}
// check for circular references and return corresponding clone
stackA || (stackA = []);
stackB || (stackB = []);
var length = stackA.length;
while (length--) {
if (stackA[length] == value) {
return stackB[length];
}
}
// add the source value to the stack of traversed objects
// and associate it with its clone
stackA.push(value);
stackB.push(result);
// recursively populate clone (susceptible to call stack limits)
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
});
return result;
}
|
The base implementation of `_.clone` without support for argument juggling
and `this` binding.
@private
@param {*} value The value to clone.
@param {boolean} [isDeep=false] Specify a deep clone.
@param {Function} [customizer] The function to customize cloning values.
@param {string} [key] The key of `value`.
@param {Object} [object] The object `value` belongs to.
@param {Array} [stackA=[]] Tracks traversed source objects.
@param {Array} [stackB=[]] Associates clones with source counterparts.
@returns {*} Returns the cloned value.
|
baseClone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseCreate(prototype) {
return isObject(prototype) ? nativeCreate(prototype) : {};
}
|
The base implementation of `_.create` without support for assigning
properties to the created object.
@private
@param {Object} prototype The object to inherit from.
@returns {Object} Returns the new object.
|
baseCreate
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseDifference(array, values) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var index = -1,
indexOf = getIndexOf(),
isCommon = indexOf == baseIndexOf,
cache = isCommon && values.length >= 200 && createCache(values),
result = [],
valuesLength = values.length;
if (cache) {
indexOf = cacheIndexOf;
isCommon = false;
values = cache;
}
outer:
while (++index < length) {
var value = array[index];
if (isCommon && value === value) {
var valuesIndex = valuesLength;
while (valuesIndex--) {
if (values[valuesIndex] === value) {
continue outer;
}
}
result.push(value);
}
else if (indexOf(values, value) < 0) {
result.push(value);
}
}
return result;
}
|
The base implementation of `_.difference` which accepts a single array
of values to exclude.
@private
@param {Array} array The array to inspect.
@param {Array} values The values to exclude.
@returns {Array} Returns the new array of filtered values.
|
baseDifference
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseEach(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwn(collection, iteratee);
}
var index = -1,
iterable = toObject(collection);
while (++index < length) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
}
|
The base implementation of `_.forEach` without support for callback
shorthands and `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array|Object|string} Returns `collection`.
|
baseEach
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseEachRight(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwnRight(collection, iteratee);
}
var iterable = toObject(collection);
while (length--) {
if (iteratee(iterable[length], length, iterable) === false) {
break;
}
}
return collection;
}
|
The base implementation of `_.forEachRight` without support for callback
shorthands and `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array|Object|string} Returns `collection`.
|
baseEachRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseEvery(collection, predicate) {
var result = true;
baseEach(collection, function(value, index, collection) {
result = !!predicate(value, index, collection);
return result;
});
return result;
}
|
The base implementation of `_.every` without support for callback
shorthands or `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {Array} Returns `true` if all elements pass the predicate check,
else `false`
|
baseEvery
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseFilter(collection, predicate) {
var result = [];
baseEach(collection, function(value, index, collection) {
if (predicate(value, index, collection)) {
result.push(value);
}
});
return result;
}
|
The base implementation of `_.filter` without support for callback
shorthands or `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {Array} Returns the new filtered array.
|
baseFilter
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseFind(collection, predicate, eachFunc, retKey) {
var result;
eachFunc(collection, function(value, key, collection) {
if (predicate(value, key, collection)) {
result = retKey ? key : value;
return false;
}
});
return result;
}
|
The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
without support for callback shorthands and `this` binding, which iterates
over `collection` using the provided `eachFunc`.
@private
@param {Array|Object|string} collection The collection to search.
@param {Function} predicate The function invoked per iteration.
@param {Function} eachFunc The function to iterate over `collection`.
@param {boolean} [retKey=false] Specify returning the key of the found
element instead of the element itself.
@returns {*} Returns the found element or its key, else `undefined`.
|
baseFind
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseFlatten(array, isDeep, isStrict, fromIndex) {
var index = (fromIndex || 0) - 1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (value && typeof value == 'object' && typeof value.length == 'number'
&& (isArray(value) || isArguments(value))) {
// recursively flatten arrays (susceptible to call stack limits)
if (isDeep) {
value = baseFlatten(value, isDeep, isStrict);
}
var valIndex = -1,
valLength = value.length;
result.length += valLength;
while (++valIndex < valLength) {
result[++resIndex] = value[valIndex];
}
} else if (!isStrict) {
result[++resIndex] = value;
}
}
return result;
}
|
The base implementation of `_.flatten` with added support for restricting
flattening and specifying the start index.
@private
@param {Array} array The array to flatten.
@param {boolean} [isDeep=false] Specify a deep flatten.
@param {boolean} [isStrict=false] Restrict flattening to arrays and `arguments` objects.
@param {number} [fromIndex=0] The index to start from.
@returns {Array} Returns the new flattened array.
|
baseFlatten
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseFor(object, iteratee, keysFunc) {
var index = -1,
iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (++index < length) {
var key = props[index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
|
The base implementation of `baseForIn` and `baseForOwn` which iterates
over `object` properties returned by `keysFunc` invoking `iteratee` for
each property. Iterator functions may exit iteration early by explicitly
returning `false`.
@private
@param {Object} object The object to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {Function} keysFunc The function to get the keys of `object`.
@returns {Object} Returns `object`.
|
baseFor
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseForRight(object, iteratee, keysFunc) {
var iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (length--) {
var key = props[length];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
|
This function is like `baseFor` except that it iterates over properties
in the opposite order.
@private
@param {Object} object The object to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {Function} keysFunc The function to get the keys of `object`.
@returns {Object} Returns `object`.
|
baseForRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseForIn(object, iteratee) {
return baseFor(object, iteratee, keysIn);
}
|
The base implementation of `_.forIn` without support for callback
shorthands and `this` binding.
@private
@param {Object} object The object to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Object} Returns `object`.
|
baseForIn
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseForOwn(object, iteratee) {
return baseFor(object, iteratee, keys);
}
|
The base implementation of `_.forOwn` without support for callback
shorthands and `this` binding.
@private
@param {Object} object The object to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Object} Returns `object`.
|
baseForOwn
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseForOwnRight(object, iteratee) {
return baseForRight(object, iteratee, keys);
}
|
The base implementation of `_.forOwnRight` without support for callback
shorthands and `this` binding.
@private
@param {Object} object The object to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Object} Returns `object`.
|
baseForOwnRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseFunctions(object, props) {
var index = -1,
length = props.length,
resIndex = -1,
result = [];
while (++index < length) {
var key = props[index];
if (isFunction(object[key])) {
result[++resIndex] = key;
}
}
return result;
}
|
The base implementation of `_.functions` which creates an array of
`object` function property names filtered from those provided.
@private
@param {Object} object The object to inspect.
@param {Array} props The property names to filter.
@returns {Array} Returns the new array of filtered property names.
|
baseFunctions
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
var result = customizer && !stackA ? customizer(value, other) : undefined;
if (typeof result != 'undefined') {
return !!result;
}
// exit early for identical values
if (value === other) {
// treat `+0` vs. `-0` as not equal
return value !== 0 || (1 / value == 1 / other);
}
var valType = typeof value,
othType = typeof other;
// exit early for unlike primitive values
if (!(valType == 'number' && othType == 'number') && (value == null || other == null ||
(valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object'))) {
return false;
}
var valClass = toString.call(value),
valIsArg = valClass == argsClass,
othClass = toString.call(other),
othIsArg = othClass == argsClass;
if (valIsArg) {
valClass = objectClass;
}
if (othIsArg) {
othClass = objectClass;
}
var valIsArr = arrayLikeClasses[valClass],
valIsErr = valClass == errorClass,
valIsObj = valClass == objectClass && !isHostObject(value),
othIsObj = othClass == objectClass && !isHostObject(other);
var isSameClass = valClass == othClass;
if (isSameClass && valIsArr) {
var valLength = value.length,
othLength = other.length;
if (valLength != othLength && !(isWhere && othLength > valLength)) {
return false;
}
}
else {
// unwrap any `lodash` wrapped values
var valWrapped = valIsObj && hasOwnProperty.call(value, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) {
return baseIsEqual(valWrapped ? value.value() : value, othWrapped ? other.value() : other, customizer, isWhere, stackA, stackB);
}
if (!isSameClass) {
return false;
}
if (valIsErr || valIsObj) {
if (!lodash.support.argsClass) {
valIsArg = isArguments(value);
othIsArg = isArguments(other);
}
// in older versions of Opera, `arguments` objects have `Array` constructors
var valCtor = valIsArg ? Object : value.constructor,
othCtor = othIsArg ? Object : other.constructor;
if (valIsErr) {
// error objects of different types are not equal
if (valCtor.prototype.name != othCtor.prototype.name) {
return false;
}
}
else {
var valHasCtor = !valIsArg && hasOwnProperty.call(value, 'constructor'),
othHasCtor = !othIsArg && hasOwnProperty.call(other, 'constructor');
if (valHasCtor != othHasCtor) {
return false;
}
if (!valHasCtor) {
// non `Object` object instances with different constructors are not equal
if (valCtor != othCtor && ('constructor' in value && 'constructor' in other) &&
!(typeof valCtor == 'function' && valCtor instanceof valCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
return false;
}
}
}
var valProps = valIsErr ? ['message', 'name'] : keys(value),
othProps = valIsErr ? valProps : keys(other);
if (valIsArg) {
valProps.push('length');
}
if (othIsArg) {
othProps.push('length');
}
valLength = valProps.length;
othLength = othProps.length;
if (valLength != othLength && !isWhere) {
return false;
}
}
else {
switch (valClass) {
case boolClass:
case dateClass:
// coerce dates and booleans to numbers, dates to milliseconds and booleans
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal
return +value == +other;
case numberClass:
// treat `NaN` vs. `NaN` as equal
return (value != +value)
? other != +other
// but treat `-0` vs. `+0` as not equal
: (value == 0 ? ((1 / value) == (1 / other)) : value == +other);
case regexpClass:
case stringClass:
// coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and
// treat strings primitives and string objects as equal
return value == String(other);
}
return false;
}
}
// assume cyclic structures are equal
// the algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
stackA || (stackA = []);
stackB || (stackB = []);
var index = stackA.length;
while (index--) {
if (stackA[index] == value) {
return stackB[index] == other;
}
}
// add `value` and `other` to the stack of traversed objects
stackA.push(value);
stackB.push(other);
// recursively compare objects and arrays (susceptible to call stack limits)
result = true;
if (valIsArr) {
// deep compare the contents, ignoring non-numeric properties
while (result && ++index < valLength) {
var valValue = value[index];
if (isWhere) {
var othIndex = othLength;
while (othIndex--) {
result = baseIsEqual(valValue, other[othIndex], customizer, isWhere, stackA, stackB);
if (result) {
break;
}
}
} else {
var othValue = other[index];
result = customizer ? customizer(valValue, othValue, index) : undefined;
if (typeof result == 'undefined') {
result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB);
}
}
}
}
else {
while (result && ++index < valLength) {
var key = valProps[index];
result = valIsErr || hasOwnProperty.call(other, key);
if (result) {
valValue = value[key];
othValue = other[key];
result = customizer ? customizer(valValue, othValue, key) : undefined;
if (typeof result == 'undefined') {
result = baseIsEqual(valValue, othValue, customizer, isWhere, stackA, stackB);
}
}
}
}
stackA.pop();
stackB.pop();
return !!result;
}
|
The base implementation of `_.isEqual`, without support for `thisArg`
binding, which allows partial "_.where" style comparisons.
@private
@param {*} value The value to compare to `other`.
@param {*} other The value to compare to `value`.
@param {Function} [customizer] The function to customize comparing values.
@param {boolean} [isWhere=false] Specify performing partial comparisons.
@param {Array} [stackA=[]] Tracks traversed `value` objects.
@param {Array} [stackB=[]] Tracks traversed `other` objects.
@returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
baseIsEqual
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseInvoke(collection, methodName, args) {
var index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
result = [];
if (isLength(length)) {
result.length = length;
}
baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]);
result[++index] = func ? func.apply(value, args) : undefined;
});
return result;
}
|
The base implementation of `_.invoke` which requires additional arguments
be provided as an array of arguments rather than individually.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|string} methodName The name of the method to invoke or
the function invoked per iteration.
@param {Array} [args] The arguments to invoke the method with.
@returns {Array} Returns the array of results.
|
baseInvoke
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseMap(collection, iteratee) {
var result = [];
baseEach(collection, function(value, key, collection) {
result.push(iteratee(value, key, collection));
});
return result;
}
|
The base implementation of `_.map` without support for callback shorthands
or `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} iteratee The function invoked per iteration.
@returns {Array} Returns the new mapped array.
|
baseMap
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseMerge(object, source, customizer, stackA, stackB) {
var isSrcArr = isArrayLike(source);
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
var isArr = isArrayLike(srcValue),
isObj = isPlainObject(srcValue),
value = object[key];
if (!(isArr || isObj)) {
result = customizer ? customizer(value, srcValue, key, object, source) : undefined;
if (typeof result == 'undefined') {
result = srcValue;
}
if (isSrcArr || typeof result != 'undefined') {
object[key] = result;
}
return;
}
// avoid merging previously merged cyclic sources
stackA || (stackA = []);
stackB || (stackB = []);
var length = stackA.length;
while (length--) {
if (stackA[length] == srcValue) {
object[key] = stackB[length];
return;
}
}
var result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isDeep = typeof result == 'undefined';
if (isDeep) {
result = isArr
? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {});
}
// add the source value to the stack of traversed objects
// and associate it with its merged value
stackA.push(srcValue);
stackB.push(result);
// recursively merge objects and arrays (susceptible to call stack limits)
if (isDeep) {
baseMerge(result, srcValue, customizer, stackA, stackB);
}
object[key] = result;
});
return object;
}
|
The base implementation of `_.merge` without support for argument juggling,
multiple sources, and `this` binding.
@private
@param {Object} object The destination object.
@param {Object} source The source object.
@param {Function} [customizer] The function to customize merging properties.
@param {Array} [stackA=[]] Tracks traversed source objects.
@param {Array} [stackB=[]] Associates values with source counterparts.
@returns {Object} Returns the destination object.
|
baseMerge
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function basePullAt(array, indexes) {
var length = indexes.length,
result = baseAt(array, indexes);
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return result;
}
|
The base implementation of `_.pullAt` without support for individual
index arguments.
@private
@param {Array} array The array to modify.
@param {number[]} indexes The indexes of elements to remove.
@returns {Array} Returns the new array of removed elements.
|
basePullAt
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseRandom(min, max) {
return min + floor(nativeRandom() * (max - min + 1));
}
|
The base implementation of `_.random` without support for argument juggling
and returning floating-point numbers.
@private
@param {number} min The minimum possible value.
@param {number} max The maximum possible value.
@returns {number} Returns the random number.
|
baseRandom
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
eachFunc(collection, function(value, index, collection) {
accumulator = initFromCollection
? (initFromCollection = false, value)
: iteratee(accumulator, value, index, collection)
});
return accumulator;
}
|
The base implementation of `_.reduce` and `_.reduceRight` without support
for callback shorthands or `this` binding, which iterates over `collection`
usingthe provided `eachFunc`.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} iteratee The function invoked per iteration.
@param {*} accumulator The initial value.
@param {boolean} initFromCollection Specify using the first or last element
of `collection` as the initial value.
@param {Function} eachFunc The function to iterate over `collection`.
@returns {*} Returns the accumulated value.
|
baseReduce
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseSome(collection, predicate) {
var result;
baseEach(collection, function(value, index, collection) {
result = predicate(value, index, collection);
return !result;
});
return !!result;
}
|
The base implementation of `_.some` without support for callback shorthands
or `this` binding.
@private
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} predicate The function invoked per iteration.
@returns {boolean} Returns `true` if any element passes the predicate check,
else `false`.
|
baseSome
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseSortedIndex(array, value, iteratee, retHighest) {
var low = 0,
high = array ? array.length : low;
value = iteratee(value);
var valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined';
while (low < high) {
var mid = floor((low + high) / 2),
computed = iteratee(array[mid]),
isReflexive = computed === computed;
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined');
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}
if (setLow) {
low = mid + 1;
} else {
high = mid;
}
}
return nativeMin(high, MAX_ARRAY_INDEX);
}
|
The base implementation of `_.sortedIndex` and `_.sortedLastIndex` without
support for callback shorthands and `this` binding.
@private
@param {Array} array The array to inspect.
@param {*} value The value to evaluate.
@param {Function} iteratee The function invoked per iteration.
@param {boolean} [retHighest=false] Specify returning the highest, instead
of the lowest, index at which a value should be inserted into `array`.
@returns {number} Returns the index at which `value` should be inserted
into `array`.
|
baseSortedIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseUniq(array, iteratee) {
var index = -1,
indexOf = getIndexOf(),
length = array.length,
isCommon = indexOf == baseIndexOf,
isLarge = isCommon && length >= 200,
seen = isLarge && createCache(),
result = [];
if (seen) {
indexOf = cacheIndexOf;
isCommon = false;
} else {
isLarge = false;
seen = iteratee ? [] : result;
}
outer:
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (isCommon && value === value) {
var seenIndex = seen.length;
while (seenIndex--) {
if (seen[seenIndex] === computed) {
continue outer;
}
}
if (iteratee) {
seen.push(computed);
}
result.push(value);
}
else if (indexOf(seen, computed) < 0) {
if (iteratee || isLarge) {
seen.push(computed);
}
result.push(value);
}
}
return result;
}
|
The base implementation of `_.uniq` without support for callback shorthands
and `this` binding.
@private
@param {Array} array The array to inspect.
@param {Function} [iteratee] The function invoked per iteration.
@returns {Array} Returns the new duplicate-value-free array.
|
baseUniq
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function baseValues(object, keysFunc) {
var index = -1,
props = keysFunc(object),
length = props.length,
result = Array(length);
while (++index < length) {
result[index] = object[props[index]];
}
return result;
}
|
The base implementation of `_.values` and `_.valuesIn` which creates an
array of `object` property values corresponding to the property names
returned by `keysFunc`.
@private
@param {Object} object The object to inspect.
@param {Function} keysFunc The function to get the keys of `object`.
@returns {Object} Returns the array of property values.
|
baseValues
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function bufferClone(buffer) {
return bufferSlice.call(buffer, 0);
}
|
Creates a clone of the given array buffer.
@private
@param {ArrayBuffer} buffer The array buffer to clone.
@returns {ArrayBuffer} Returns the cloned array buffer.
|
bufferClone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function clonePassthru(value) {
return isCloneable(value) ? undefined : value;
}
|
Used by `_.matches` to clone `source` values, letting uncloneable values
passthu instead of returning empty objects.
@private
@param {*} value The value to clone.
@returns {*} Returns the cloned value.
|
clonePassthru
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function composeArgs(args, partials, holders) {
var holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
leftIndex = -1,
leftLength = partials.length,
result = Array(argsLength + leftLength);
while (++leftIndex < leftLength) {
result[leftIndex] = partials[leftIndex];
}
while (++argsIndex < holdersLength) {
result[holders[argsIndex]] = args[argsIndex];
}
while (argsLength--) {
result[leftIndex++] = args[argsIndex++];
}
return result;
}
|
Creates an array that is the composition of partially applied arguments,
placeholders, and provided arguments into a single array of arguments.
@private
@param {Array|Object} args The provided arguments.
@param {Array} partials The arguments to prepend to those provided.
@param {Array} holders The `partials` placeholder indexes.
@returns {Array} Returns the new array of composed arguments.
|
composeArgs
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function composeArgsRight(args, partials, holders) {
var holdersIndex = -1,
holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
rightIndex = -1,
rightLength = partials.length,
result = Array(argsLength + rightLength);
while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex];
}
var pad = argsIndex;
while (++rightIndex < rightLength) {
result[pad + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
result[pad + holders[holdersIndex]] = args[argsIndex++];
}
return result;
}
|
This function is like `composeArgs` except that the arguments composition
is tailored for `_.partialRight`.
@private
@param {Array|Object} args The provided arguments.
@param {Array} partials The arguments to append to those provided.
@param {Array} holders The `partials` placeholder indexes.
@returns {Array} Returns the new array of composed arguments.
|
composeArgsRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createAggregator(setter, initializer) {
return function(collection, iteratee, thisArg) {
iteratee = getCallback(iteratee, thisArg, 3);
var result = initializer ? initializer() : {};
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
setter(result, value, iteratee(value, index, collection), collection);
}
} else {
baseEach(collection, function(value, key, collection) {
setter(result, value, iteratee(value, key, collection), collection);
});
}
return result;
};
}
|
Creates a function that aggregates a collection, creating an accumulator
object composed from the results of running each element in the collection
through `iteratee`. The given setter function sets the keys and values of
the accumulator object. If `initializer` is provided it is used to initialize
the accumulator object.
@private
@param {Function} setter The function to set keys and values of the accumulator object.
@param {Function} [initializer] The function to initialize the accumulator object.
@returns {Function} Returns the new aggregator function.
|
createAggregator
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createAssigner(assigner) {
return function() {
var length = arguments.length,
object = arguments[0];
if (length < 2 || object == null) {
return object;
}
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
length = 2;
}
// juggle arguments
if (length > 3 && typeof arguments[length - 2] == 'function') {
var customizer = baseCallback(arguments[--length - 1], arguments[length--], 5);
} else if (length > 2 && typeof arguments[length - 1] == 'function') {
customizer = arguments[--length];
}
var index = 0;
while (++index < length) {
assigner(object, arguments[index], customizer);
}
return object;
};
}
|
Creates a function that assigns properties of source object(s) to a given
destination object.
@private
@param {Function} assigner The function to handle assigning values.
@returns {Function} Returns the new assigner function.
|
createAssigner
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.