Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Stack strategies
(version: 0)
Comparing performance of:
generators vs Manual vs Vanilla vs Jumper
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
generators
var GAS = 0; function run(init, makeGen) { GAS = init; var gen = makeGen(); while(true) { var res = gen.next(); if(res.done) { return res.value; } else { GAS = init; continue; } } } var linkNames = ["first", "rest"]; function* link(f, r) { return { $name: "link", $fields: linkNames, first: f, rest: r } } var empty = { $name: "empty" }; function* map(f, l) { if(GAS-- <= 0) { yield null; } var ans; var dispatch = { empty: 0, link: 1 }; var case_step = dispatch[l.$name]; switch(case_step) { case 0: ans = empty break; case 1: fst = l[l.$fields[0]]; rst = l[l.$fields[1]]; var t1 = yield* f(fst); var t2 = yield* map(f, rst); var t3 = yield* link(t1, t2); ans = t3; } return ans; } var buildList = function(n) { var l = empty; for(var i = 0; i < n; i++) { l = link(i, l).next().value; } return l; } run(100, function*() { return yield* map(function*(l) { return l + 1; }, buildList(1000)); });
Manual
var GAS = 0; function run(init, runner) { GAS = init; var frames = [{ run: runner }]; var thisFrame = frames.pop(); while(true) { var res = thisFrame.run(thisFrame); if(res.isCont) { var len = res.frames.length; for(var i = 0; i < len; i++) { frames.push(res.frames.pop()); } GAS = init; thisFrame = frames.pop(); } else { if(frames.length <= 0) { break; } thisFrame = frames.pop(); thisFrame.ans = res; } } return res; } var linkNames = ["first", "rest"]; function link(f, r) { return { $name: "link", $fields: linkNames, first: f, rest: r } } var empty = { $name: "empty" }; function map(f, l) { var step = 0; if(f.isFrame) { var ans = f.ans; step = f.step; var t1 = f.vars[0]; var fst = f.vars[1]; var rst = f.vars[2]; var t2 = f.vars[3]; l = f.args[1]; f = f.args[0]; } if(GAS-- <= 0) { return { isCont: true, frames: [{ run: map, isFrame: true, vars: [t1, fst, rst, t2], args: [f, l], step: step }] }; } while(true) { switch(step) { case 0: var dispatch = { empty: 1, link: 2 }; step = dispatch[l.$name]; break; case 1: ans = empty step = 5 break; case 2: fst = l[l.$fields[0]]; rst = l[l.$fields[1]]; step = 3; ans = f(fst); break; case 3: t1 = ans; step = 4 ans = map(f, rst); break; case 4: t2 = ans; step = 5 ans = link(t1, t2); break; case 5: GAS++; return ans; } if(ans && ans.isCont) { ans.frames.push({ run: map, isFrame: true, vars: [t1, fst, rst, t2], args: [f, l], step: step }); return ans; } } } var buildList = function(n) { var l = empty; for(var i = 0; i < n; i++) { l = link(i, l); } return l; } run(100, function() { return map(function(l) { return l + 1; }, buildList(1000)); });
Vanilla
let linkNames = ['first', 'rest']; let empty = { $name: 'empty' }; function map(f, l) { var dispatch = { empty: 0, link: 1, }; var case_step = dispatch[l.$name]; switch (case_step) { case 0: return empty; case 1: fst = l[l.$fields[0]]; rst = l[l.$fields[1]]; let a = f(fst); let b = map(f, rst); let c = link(a, b); return c; } } function link(f, r) { return { $name: 'link', $fields: linkNames, first: f, rest: r }; } function buildList(n) { var l = empty; for (var i = 0; i < n; i++) { l = link(i, l); } return l; } map(function (l) { return l + 1; }, buildList(1000));
Jumper
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function (global){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const assert = require('assert'); exports.stack = []; exports.mode = 'normal'; // We throw this exception when a continuation value is applied. i.e., // callCC applies its argument to a function that throws this exception. class Restore { constructor(stack) { this.stack = stack; } } exports.Restore = Restore; // We throw this exception to capture the current continuation. i.e., // callCC throws this exception when it is applied. class Capture { constructor(f, stack) { this.f = f; this.stack = stack; } } exports.Capture = Capture; function callCC(f) { throw new Capture(f, []); } exports.callCC = callCC; // Helper function that constructs a top-of-stack frame. function topK(f) { return { kind: 'top', f: () => { exports.stack = []; exports.mode = 'normal'; return f(); } }; } exports.topK = topK; // Wraps a stack in a function that throws an exception to discard the current // continuation. The exception carries the provided stack with a final frame // that returns the supplied value. function makeCont(stack) { return function (v) { throw new Restore([topK(() => v), ...stack]); }; } exports.makeCont = makeCont; function restore(aStack) { assert(aStack.length > 0); exports.mode = 'restoring'; exports.stack = aStack; exports.stack[exports.stack.length - 1].f(); } exports.restore = restore; function runtime(body) { try { body(); } catch (exn) { if (exn instanceof Capture) { // Recursive call to runtime addresses nested continuations. The return // statement ensures that the invocation is in tail position. // At this point, exn.stack is the continuation of callCC, but doesn’t have // a top-of-stack frame that actually restores the saved continuation. We // need to apply the function passed to callCC to the stack here, because // this is the only point where the whole stack is ready. return runtime(() => // Doing exn.f makes "this" wrong. restore([topK(() => exn.f.call(global, makeCont(exn.stack))), ...exn.stack])); } else if (exn instanceof Restore) { // The current continuation has been discarded and we now restore the // continuation in exn. return runtime(() => restore([...exn.stack])); } else { throw exn; // userland exception } } } exports.runtime = runtime; const knownBuiltIns = [Object, Function, Boolean, Symbol, Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, Number, Math, Date, String, RegExp, Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, Map, Set, WeakMap, WeakSet]; function handleNew(constr, ...args) { if (knownBuiltIns.includes(constr)) { return new constr(...args); } let obj; if (exports.mode === "normal") { obj = Object.create(constr.prototype); } else { const frame = exports.stack[exports.stack.length - 1]; if (frame.kind === "rest") { [obj] = frame.locals; } else { throw "bad"; } exports.stack.pop(); } try { if (exports.mode === "normal") { constr.apply(obj, args); } else { exports.stack[exports.stack.length - 1].f.apply(obj, []); } } catch (exn) { if (exn instanceof Capture) { exn.stack.push({ kind: "rest", f: () => handleNew(constr, ...args), locals: [obj], index: 0 }); } throw exn; } return obj; } exports.handleNew = handleNew; let countDown; function suspend(interval, top) { if (Number.isNaN(interval)) { return; } if (countDown === undefined) { countDown = interval; } if (--countDown === 0) { countDown = interval; return callCC(top); } } exports.suspend = suspend; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"assert":3}],2:[function(require,module,exports){ const s = Date.now(); ((function ($isStop, $onStop, $onDone, $interval) { const $__R = require("stopify/built/src/callcc/runtime"); function $program() { let target = null; let _app7 = { box: void 0 }; let $result = { box: void 0 }; let $handleNew = { box: void 0 }; let $knownBuiltIns = { box: void 0 }; if ($__R.mode === "restoring") { const _locals6 = $__R.stack[$__R.stack.length - 1].locals; _app7 = _locals6[0]; $result = _locals6[1]; $handleNew = _locals6[2]; $knownBuiltIns = _locals6[3]; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } $__R.mode === "normal" ? $knownBuiltIns.box = [Object, Function, Boolean, Symbol, Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, Number, Math, Date, String, RegExp, Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, Map, Set, WeakMap, WeakSet] : void 0; $__R.mode === "normal" ? $handleNew.box = $__R.handleNew : void 0; try { if ($__R.mode === "normal") { $result.box = $__R.callCC(function _funExpr($top) { let target = null; let _app5 = { box: void 0 }; let _app6 = { box: void 0 }; let empty = { box: void 0 }; let linkNames = { box: void 0 }; var fst = { box: void 0 }; var rst = { box: void 0 }; if ($__R.mode === "restoring") { const _locals5 = $__R.stack[$__R.stack.length - 1].locals; _app5 = _locals5[0]; _app6 = _locals5[1]; empty = _locals5[2]; linkNames = _locals5[3]; fst = _locals5[4]; rst = _locals5[5]; map = _locals5[6]; link = _locals5[7]; buildList = _locals5[8]; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } $__R.mode === "normal" ? rst.box = void 0 : void 0; $__R.mode === "normal" ? fst.box = void 0 : void 0; $__R.mode === "normal" ? linkNames.box = ['first', 'rest'] : void 0; $__R.mode === "normal" ? empty.box = { $name: 'empty' } : void 0; function map(f, l) { let target = null; let c = { box: void 0 }; let b = { box: void 0 }; let a = { box: void 0 }; let _fallthrough = { box: void 0 }; let _test = { box: void 0 }; var case_step = { box: void 0 }; var dispatch = { box: void 0 }; let _app = { box: void 0 }; if ($__R.mode === "restoring") { const _locals = $__R.stack[$__R.stack.length - 1].locals; c = _locals[0]; b = _locals[1]; a = _locals[2]; _fallthrough = _locals[3]; _test = _locals[4]; case_step = _locals[5]; dispatch = _locals[6]; _app = _locals[7]; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } try { if ($__R.mode === "normal") { _app.box = $__R.suspend($interval, $top); } else { if (target === 1) { _app.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => map.call(this, f, l), locals: [c, b, a, _fallthrough, _test, case_step, dispatch, _app], index: 1 }); } throw exn; } _app.box; $__R.mode === "normal" ? dispatch.box = { empty: 0, link: 1 } : void 0; $__R.mode === "normal" ? case_step.box = dispatch.box[l.$name] : void 0; _switch: { $__R.mode === "normal" ? _test.box = case_step.box : void 0; $__R.mode === "normal" ? _fallthrough.box = false : void 0; if ($__R.mode === "restoring" && false || $__R.mode === "normal" && (_test.box === 0 || _fallthrough.box)) { $__R.mode === "normal" ? _fallthrough.box = true : void 0; return empty.box; } else if ($__R.mode === "restoring" && false || $__R.mode === "normal") { ; } if ($__R.mode === "restoring" && (target === 4 || target === 3 || target === 2 || false) || $__R.mode === "normal" && (_test.box === 1 || _fallthrough.box)) { $__R.mode === "normal" ? _fallthrough.box = true : void 0; $__R.mode === "normal" ? fst.box = l[l.$fields[0]] : void 0; $__R.mode === "normal" ? rst.box = l[l.$fields[1]] : void 0; try { if ($__R.mode === "normal") { a.box = f(fst.box); } else { if (target === 2) { a.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => map.call(this, f, l), locals: [c, b, a, _fallthrough, _test, case_step, dispatch, _app], index: 2 }); } throw exn; } try { if ($__R.mode === "normal") { b.box = map(f, rst.box); } else { if (target === 3) { b.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => map.call(this, f, l), locals: [c, b, a, _fallthrough, _test, case_step, dispatch, _app], index: 3 }); } throw exn; } try { if ($__R.mode === "normal") { c.box = link(a.box, b.box); } else { if (target === 4) { c.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => map.call(this, f, l), locals: [c, b, a, _fallthrough, _test, case_step, dispatch, _app], index: 4 }); } throw exn; } return c.box; } else if ($__R.mode === "restoring" && false || $__R.mode === "normal") { ; } } } function link(f, r) { let target = null; if ($__R.mode === "restoring") { const _locals2 = $__R.stack[$__R.stack.length - 1].locals; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } return { $name: 'link', $fields: linkNames.box, first: f, rest: r }; } function buildList(n) { let target = null; let _app4 = { box: void 0 }; let _app3 = { box: void 0 }; var i = { box: void 0 }; var l = { box: void 0 }; let _app2 = { box: void 0 }; if ($__R.mode === "restoring") { const _locals3 = $__R.stack[$__R.stack.length - 1].locals; _app4 = _locals3[0]; _app3 = _locals3[1]; i = _locals3[2]; l = _locals3[3]; _app2 = _locals3[4]; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } try { if ($__R.mode === "normal") { _app2.box = $__R.suspend($interval, $top); } else { if (target === 5) { _app2.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => buildList.call(this, n), locals: [_app4, _app3, i, l, _app2], index: 5 }); } throw exn; } _app2.box; $__R.mode === "normal" ? l.box = empty.box : void 0; { $__R.mode === "normal" ? i.box = 0 : void 0; _loop_break: while ($__R.mode === "restoring" && (target === 7 || target === 6 || false) || $__R.mode === "normal" && i.box < n) { _loop_continue: { try { if ($__R.mode === "normal") { _app3.box = $__R.suspend($interval, $top); } else { if (target === 6) { _app3.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => buildList.call(this, n), locals: [_app4, _app3, i, l, _app2], index: 6 }); } throw exn; } _app3.box; try { if ($__R.mode === "normal") { _app4.box = link(i.box, l.box); } else { if (target === 7) { _app4.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => buildList.call(this, n), locals: [_app4, _app3, i, l, _app2], index: 7 }); } throw exn; } $__R.mode === "normal" ? l.box = _app4.box : void 0; } $__R.mode === "normal" ? i.box++ : void 0; } } return l.box; } try { if ($__R.mode === "normal") { _app6.box = buildList(1000); } else { if (target === 8) { _app6.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => _funExpr.call(this, $top), locals: [_app5, _app6, empty, linkNames, fst, rst, map, link, buildList], index: 8 }); } throw exn; } try { if ($__R.mode === "normal") { _app5.box = map(function _funExpr2(l) { let target = null; if ($__R.mode === "restoring") { const _locals4 = $__R.stack[$__R.stack.length - 1].locals; target = $__R.stack[$__R.stack.length - 1].index; $__R.stack.pop(); } return l + 1; }, _app6.box); } else { if (target === 9) { _app5.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => _funExpr.call(this, $top), locals: [_app5, _app6, empty, linkNames, fst, rst, map, link, buildList], index: 9 }); } throw exn; } _app5.box; return "done"; }); } else { if (target === 0) { $result.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => $program.call(this), locals: [_app7, $result, $handleNew, $knownBuiltIns], index: 0 }); } throw exn; } if ($__R.mode === "restoring" && (target === 10 || false) || $__R.mode === "normal" && $result.box === "done") { if ($__R.mode === "normal") return $onDone();else if ($__R.mode === "restoring" && (target === 10 || false)) return $__R.stack[$__R.stack.length - 1].f(); } else if ($__R.mode === "restoring" && (target === 13 || target === 12 || target === 11 || false) || $__R.mode === "normal") { try { if ($__R.mode === "normal") { _app7.box = $isStop(); } else { if (target === 11) { _app7.box = $__R.stack[$__R.stack.length - 1].f(); } } } catch (exn) { if (exn instanceof $__R.Capture) { exn.stack.push({ kind: "rest", f: () => $program.call(this), locals: [_app7, $result, $handleNew, $knownBuiltIns], index: 11 }); } throw exn; } if ($__R.mode === "restoring" && (target === 12 || false) || $__R.mode === "normal" && _app7.box) { if ($__R.mode === "normal") return $onStop();else if ($__R.mode === "restoring" && (target === 12 || false)) return $__R.stack[$__R.stack.length - 1].f(); } else if ($__R.mode === "restoring" && (target === 13 || false) || $__R.mode === "normal") { if ($__R.mode === "normal") return setTimeout(function _funExpr3() { return $__R.runtime($result.box); }, 0);else if ($__R.mode === "restoring" && (target === 13 || false)) return $__R.stack[$__R.stack.length - 1].f(); } } } return $__R.runtime($program); })).call(this, _ => false, () => 0, () => { console.error('Compilation time: 193ms') const e = Date.now(); // s is defined at the start of the program console.error("Runtime: " + (e - s) + "ms"); }, // |INTERVAL| undefined) },{"stopify/built/src/callcc/runtime":1}],3:[function(require,module,exports){ (function (global){ 'use strict'; // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js // original notice: /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * @license MIT */ function compare(a, b) { if (a === b) { return 0; } var x = a.length; var y = b.length; for (var i = 0, len = Math.min(x, y); i < len; ++i) { if (a[i] !== b[i]) { x = a[i]; y = b[i]; break; } } if (x < y) { return -1; } if (y < x) { return 1; } return 0; } function isBuffer(b) { if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { return global.Buffer.isBuffer(b); } return !!(b != null && b._isBuffer); } // based on node assert, original notice: // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 // // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! // // Originally from narwhal.js (http://narwhaljs.org) // Copyright (c) 2009 Thomas Robinson <280north.com> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the 'Software'), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. var util = require('util/'); var hasOwn = Object.prototype.hasOwnProperty; var pSlice = Array.prototype.slice; var functionsHaveNames = (function () { return function foo() {}.name === 'foo'; }()); function pToString (obj) { return Object.prototype.toString.call(obj); } function isView(arrbuf) { if (isBuffer(arrbuf)) { return false; } if (typeof global.ArrayBuffer !== 'function') { return false; } if (typeof ArrayBuffer.isView === 'function') { return ArrayBuffer.isView(arrbuf); } if (!arrbuf) { return false; } if (arrbuf instanceof DataView) { return true; } if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { return true; } return false; } // 1. The assert module provides functions that throw // AssertionError's when particular conditions are not met. The // assert module must conform to the following interface. var assert = module.exports = ok; // 2. The AssertionError is defined in assert. // new assert.AssertionError({ message: message, // actual: actual, // expected: expected }) var regex = /\s*function\s+([^\(\s]*)\s*/; // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js function getName(func) { if (!util.isFunction(func)) { return; } if (functionsHaveNames) { return func.name; } var str = func.toString(); var match = str.match(regex); return match && match[1]; } assert.AssertionError = function AssertionError(options) { this.name = 'AssertionError'; this.actual = options.actual; this.expected = options.expected; this.operator = options.operator; if (options.message) { this.message = options.message; this.generatedMessage = false; } else { this.message = getMessage(this); this.generatedMessage = true; } var stackStartFunction = options.stackStartFunction || fail; if (Error.captureStackTrace) { Error.captureStackTrace(this, stackStartFunction); } else { // non v8 browsers so we can have a stacktrace var err = new Error(); if (err.stack) { var out = err.stack; // try to strip useless frames var fn_name = getName(stackStartFunction); var idx = out.indexOf('\n' + fn_name); if (idx >= 0) { // once we have located the function frame // we need to strip out everything before it (and its line) var next_line = out.indexOf('\n', idx + 1); out = out.substring(next_line + 1); } this.stack = out; } } }; // assert.AssertionError instanceof Error util.inherits(assert.AssertionError, Error); function truncate(s, n) { if (typeof s === 'string') { return s.length < n ? s : s.slice(0, n); } else { return s; } } function inspect(something) { if (functionsHaveNames || !util.isFunction(something)) { return util.inspect(something); } var rawname = getName(something); var name = rawname ? ': ' + rawname : ''; return '[Function' + name + ']'; } function getMessage(self) { return truncate(inspect(self.actual), 128) + ' ' + self.operator + ' ' + truncate(inspect(self.expected), 128); } // At present only the three keys mentioned above are used and // understood by the spec. Implementations or sub modules can pass // other keys to the AssertionError's constructor - they will be // ignored. // 3. All of the following functions must throw an AssertionError // when a corresponding condition is not met, with a message that // may be undefined if not provided. All assertion methods provide // both the actual and expected values to the assertion error for // display purposes. function fail(actual, expected, message, operator, stackStartFunction) { throw new assert.AssertionError({ message: message, actual: actual, expected: expected, operator: operator, stackStartFunction: stackStartFunction }); } // EXTENSION! allows for well behaved errors defined elsewhere. assert.fail = fail; // 4. Pure assertion tests whether a value is truthy, as determined // by !!guard. // assert.ok(guard, message_opt); // This statement is equivalent to assert.equal(true, !!guard, // message_opt);. To test strictly for the value true, use // assert.strictEqual(true, guard, message_opt);. function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); } assert.ok = ok; // 5. The equality assertion tests shallow, coercive equality with // ==. // assert.equal(actual, expected, message_opt); assert.equal = function equal(actual, expected, message) { if (actual != expected) fail(actual, expected, message, '==', assert.equal); }; // 6. The non-equality assertion tests for whether two objects are not equal // with != assert.notEqual(actual, expected, message_opt); assert.notEqual = function notEqual(actual, expected, message) { if (actual == expected) { fail(actual, expected, message, '!=', assert.notEqual); } }; // 7. The equivalence assertion tests a deep equality relation. // assert.deepEqual(actual, expected, message_opt); assert.deepEqual = function deepEqual(actual, expected, message) { if (!_deepEqual(actual, expected, false)) { fail(actual, expected, message, 'deepEqual', assert.deepEqual); } }; assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { if (!_deepEqual(actual, expected, true)) { fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual); } }; function _deepEqual(actual, expected, strict, memos) { // 7.1. All identical values are equivalent, as determined by ===. if (actual === expected) { return true; } else if (isBuffer(actual) && isBuffer(expected)) { return compare(actual, expected) === 0; // 7.2. If the expected value is a Date object, the actual value is // equivalent if it is also a Date object that refers to the same time. } else if (util.isDate(actual) && util.isDate(expected)) { return actual.getTime() === expected.getTime(); // 7.3 If the expected value is a RegExp object, the actual value is // equivalent if it is also a RegExp object with the same source and // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). } else if (util.isRegExp(actual) && util.isRegExp(expected)) { return actual.source === expected.source && actual.global === expected.global && actual.multiline === expected.multiline && actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase; // 7.4. Other pairs that do not both pass typeof value == 'object', // equivalence is determined by ==. } else if ((actual === null || typeof actual !== 'object') && (expected === null || typeof expected !== 'object')) { return strict ? actual === expected : actual == expected; // If both values are instances of typed arrays, wrap their underlying // ArrayBuffers in a Buffer each to increase performance // This optimization requires the arrays to have the same type as checked by // Object.prototype.toString (aka pToString). Never perform binary // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their // bit patterns are not identical. } else if (isView(actual) && isView(expected) && pToString(actual) === pToString(expected) && !(actual instanceof Float32Array || actual instanceof Float64Array)) { return compare(new Uint8Array(actual.buffer), new Uint8Array(expected.buffer)) === 0; // 7.5 For all other Object pairs, including Array objects, equivalence is // determined by having the same number of owned properties (as verified // with Object.prototype.hasOwnProperty.call), the same set of keys // (although not necessarily the same order), equivalent values for every // corresponding key, and an identical 'prototype' property. Note: this // accounts for both named and indexed properties on Arrays. } else if (isBuffer(actual) !== isBuffer(expected)) { return false; } else { memos = memos || {actual: [], expected: []}; var actualIndex = memos.actual.indexOf(actual); if (actualIndex !== -1) { if (actualIndex === memos.expected.indexOf(expected)) { return true; } } memos.actual.push(actual); memos.expected.push(expected); return objEquiv(actual, expected, strict, memos); } } function isArguments(object) { return Object.prototype.toString.call(object) == '[object Arguments]'; } function objEquiv(a, b, strict, actualVisitedObjects) { if (a === null || a === undefined || b === null || b === undefined) return false; // if one is a primitive, the other must be same if (util.isPrimitive(a) || util.isPrimitive(b)) return a === b; if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false; var aIsArgs = isArguments(a); var bIsArgs = isArguments(b); if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) return false; if (aIsArgs) { a = pSlice.call(a); b = pSlice.call(b); return _deepEqual(a, b, strict); } var ka = objectKeys(a); var kb = objectKeys(b); var key, i; // having the same number of owned properties (keys incorporates // hasOwnProperty) if (ka.length !== kb.length) return false; //the same set of keys (although not necessarily the same order), ka.sort(); kb.sort(); //~~~cheap key test for (i = ka.length - 1; i >= 0; i--) { if (ka[i] !== kb[i]) return false; } //equivalent values for every corresponding key, and //~~~possibly expensive deep test for (i = ka.length - 1; i >= 0; i--) { key = ka[i]; if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects)) return false; } return true; } // 8. The non-equivalence assertion tests for any deep inequality. // assert.notDeepEqual(actual, expected, message_opt); assert.notDeepEqual = function notDeepEqual(actual, expected, message) { if (_deepEqual(actual, expected, false)) { fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); } }; assert.notDeepStrictEqual = notDeepStrictEqual; function notDeepStrictEqual(actual, expected, message) { if (_deepEqual(actual, expected, true)) { fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual); } } // 9. The strict equality assertion tests strict equality, as determined by ===. // assert.strictEqual(actual, expected, message_opt); assert.strictEqual = function strictEqual(actual, expected, message) { if (actual !== expected) { fail(actual, expected, message, '===', assert.strictEqual); } }; // 10. The strict non-equality assertion tests for strict inequality, as // determined by !==. assert.notStrictEqual(actual, expected, message_opt); assert.notStrictEqual = function notStrictEqual(actual, expected, message) { if (actual === expected) { fail(actual, expected, message, '!==', assert.notStrictEqual); } }; function expectedException(actual, expected) { if (!actual || !expected) { return false; } if (Object.prototype.toString.call(expected) == '[object RegExp]') { return expected.test(actual); } try { if (actual instanceof expected) { return true; } } catch (e) { // Ignore. The instanceof check doesn't work for arrow functions. } if (Error.isPrototypeOf(expected)) { return false; } return expected.call({}, actual) === true; } function _tryBlock(block) { var error; try { block(); } catch (e) { error = e; } return error; } function _throws(shouldThrow, block, expected, message) { var actual; if (typeof block !== 'function') { throw new TypeError('"block" argument must be a function'); } if (typeof expected === 'string') { message = expected; expected = null; } actual = _tryBlock(block); message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + (message ? ' ' + message : '.'); if (shouldThrow && !actual) { fail(actual, expected, 'Missing expected exception' + message); } var userProvidedMessage = typeof message === 'string'; var isUnwantedException = !shouldThrow && util.isError(actual); var isUnexpectedException = !shouldThrow && actual && !expected; if ((isUnwantedException && userProvidedMessage && expectedException(actual, expected)) || isUnexpectedException) { fail(actual, expected, 'Got unwanted exception' + message); } if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) { throw actual; } } // 11. Expected to throw an error: // assert.throws(block, Error_opt, message_opt); assert.throws = function(block, /*optional*/error, /*optional*/message) { _throws(true, block, error, message); }; // EXTENSION! This is annoying to write outside this module. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { _throws(false, block, error, message); }; assert.ifError = function(err) { if (err) throw err; }; var objectKeys = Object.keys || function (obj) { var keys = []; for (var key in obj) { if (hasOwn.call(obj, key)) keys.push(key); } return keys; }; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"util/":7}],4:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; },{}],5:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { ctor.super_ = superCtor ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; } else { // old school shim for old browsers module.exports = function inherits(ctor, superCtor) { ctor.super_ = superCtor var TempCtor = function () {} TempCtor.prototype = superCtor.prototype ctor.prototype = new TempCtor() ctor.prototype.constructor = ctor } } },{}],6:[function(require,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } },{}],7:[function(require,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. var formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (!isString(f)) { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': try { return JSON.stringify(args[i++]); } catch (_) { return '[Circular]'; } default: return x; } }); for (var x = args[i]; i < len; x = args[++i]) { if (isNull(x) || !isObject(x)) { str += ' ' + x; } else { str += ' ' + inspect(x); } } return str; }; // Mark that a method should not be used. // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. exports.deprecate = function(fn, msg) { // Allow for deprecating things in the process of starting up. if (isUndefined(global.process)) { return function() { return exports.deprecate(fn, msg).apply(this, arguments); }; } if (process.noDeprecation === true) { return fn; } var warned = false; function deprecated() { if (!warned) { if (process.throwDeprecation) { throw new Error(msg); } else if (process.traceDeprecation) { console.trace(msg); } else { console.error(msg); } warned = true; } return fn.apply(this, arguments); } return deprecated; }; var debugs = {}; var debugEnviron; exports.debuglog = function(set) { if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || ''; set = set.toUpperCase(); if (!debugs[set]) { if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { var pid = process.pid; debugs[set] = function() { var msg = exports.format.apply(exports, arguments); console.error('%s %d: %s', set, pid, msg); }; } else { debugs[set] = function() {}; } } return debugs[set]; }; /** * Echos the value of a value. Trys to print the value out * in the best way possible given the different types. * * @param {Object} obj The object to print out. * @param {Object} opts Optional options object that alters the output. */ /* legacy: obj, showHidden, depth, colors*/ function inspect(obj, opts) { // default options var ctx = { seen: [], stylize: stylizeNoColor }; // legacy... if (arguments.length >= 3) ctx.depth = arguments[2]; if (arguments.length >= 4) ctx.colors = arguments[3]; if (isBoolean(opts)) { // legacy... ctx.showHidden = opts; } else if (opts) { // got an "options" object exports._extend(ctx, opts); } // set default options if (isUndefined(ctx.showHidden)) ctx.showHidden = false; if (isUndefined(ctx.depth)) ctx.depth = 2; if (isUndefined(ctx.colors)) ctx.colors = false; if (isUndefined(ctx.customInspect)) ctx.customInspect = true; if (ctx.colors) ctx.stylize = stylizeWithColor; return formatValue(ctx, obj, ctx.depth); } exports.inspect = inspect; // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics inspect.colors = { 'bold' : [1, 22], 'italic' : [3, 23], 'underline' : [4, 24], 'inverse' : [7, 27], 'white' : [37, 39], 'grey' : [90, 39], 'black' : [30, 39], 'blue' : [34, 39], 'cyan' : [36, 39], 'green' : [32, 39], 'magenta' : [35, 39], 'red' : [31, 39], 'yellow' : [33, 39] }; // Don't use 'blue' not visible on cmd.exe inspect.styles = { 'special': 'cyan', 'number': 'yellow', 'boolean': 'yellow', 'undefined': 'grey', 'null': 'bold', 'string': 'green', 'date': 'magenta', // "name": intentionally not styling 'regexp': 'red' }; function stylizeWithColor(str, styleType) { var style = inspect.styles[styleType]; if (style) { return '\u001b[' + inspect.colors[style][0] + 'm' + str + '\u001b[' + inspect.colors[style][1] + 'm'; } else { return str; } } function stylizeNoColor(str, styleType) { return str; } function arrayToHash(array) { var hash = {}; array.forEach(function(val, idx) { hash[val] = true; }); return hash; } function formatValue(ctx, value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { var ret = value.inspect(recurseTimes, ctx); if (!isString(ret)) { ret = formatValue(ctx, ret, recurseTimes); } return ret; } // Primitive types cannot have properties var primitive = formatPrimitive(ctx, value); if (primitive) { return primitive; } // Look up the keys of the object. var keys = Object.keys(value); var visibleKeys = arrayToHash(keys); if (ctx.showHidden) { keys = Object.getOwnPropertyNames(value); } // IE doesn't make error fields non-enumerable // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { return formatError(value); } // Some type of object without properties can be shortcutted. if (keys.length === 0) { if (isFunction(value)) { var name = value.name ? ': ' + value.name : ''; return ctx.stylize('[Function' + name + ']', 'special'); } if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } if (isDate(value)) { return ctx.stylize(Date.prototype.toString.call(value), 'date'); } if (isError(value)) { return formatError(value); } } var base = '', array = false, braces = ['{', '}']; // Make Array say that they are Array if (isArray(value)) { array = true; braces = ['[', ']']; } // Make functions say that they are functions if (isFunction(value)) { var n = value.name ? ': ' + value.name : ''; base = ' [Function' + n + ']'; } // Make RegExps say that they are RegExps if (isRegExp(value)) { base = ' ' + RegExp.prototype.toString.call(value); } // Make dates with properties first say the date if (isDate(value)) { base = ' ' + Date.prototype.toUTCString.call(value); } // Make error with message first say the error if (isError(value)) { base = ' ' + formatError(value); } if (keys.length === 0 && (!array || value.length == 0)) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); } else { return ctx.stylize('[Object]', 'special'); } } ctx.seen.push(value); var output; if (array) { output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); } else { output = keys.map(function(key) { return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); }); } ctx.seen.pop(); return reduceToSingleString(output, base, braces); } function formatPrimitive(ctx, value) { if (isUndefined(value)) return ctx.stylize('undefined', 'undefined'); if (isString(value)) { var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') + '\''; return ctx.stylize(simple, 'string'); } if (isNumber(value)) return ctx.stylize('' + value, 'number'); if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here. if (isNull(value)) return ctx.stylize('null', 'null'); } function formatError(value) { return '[' + Error.prototype.toString.call(value) + ']'; } function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; for (var i = 0, l = value.length; i < l; ++i) { if (hasOwnProperty(value, String(i))) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true)); } else { output.push(''); } } keys.forEach(function(key) { if (!key.match(/^\d+$/)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } }); return output; } function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { var name, str, desc; desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; if (desc.get) { if (desc.set) { str = ctx.stylize('[Getter/Setter]', 'special'); } else { str = ctx.stylize('[Getter]', 'special'); } } else { if (desc.set) { str = ctx.stylize('[Setter]', 'special'); } } if (!hasOwnProperty(visibleKeys, key)) { name = '[' + key + ']'; } if (!str) { if (ctx.seen.indexOf(desc.value) < 0) { if (isNull(recurseTimes)) { str = formatValue(ctx, desc.value, null); } else { str = formatValue(ctx, desc.value, recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (array) { str = str.split('\n').map(function(line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); } } } else { str = ctx.stylize('[Circular]', 'special'); } } if (isUndefined(name)) { if (array && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = ctx.stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'"); name = ctx.stylize(name, 'string'); } } return name + ': ' + str; } function reduceToSingleString(output, base, braces) { var numLinesEst = 0; var length = output.reduce(function(prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; }, 0); if (length > 60) { return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } // NOTE: These type checking functions intentionally don't use `instanceof` // because it is fragile and can be easily faked with `Object.create()`. function isArray(ar) { return Array.isArray(ar); } exports.isArray = isArray; function isBoolean(arg) { return typeof arg === 'boolean'; } exports.isBoolean = isBoolean; function isNull(arg) { return arg === null; } exports.isNull = isNull; function isNullOrUndefined(arg) { return arg == null; } exports.isNullOrUndefined = isNullOrUndefined; function isNumber(arg) { return typeof arg === 'number'; } exports.isNumber = isNumber; function isString(arg) { return typeof arg === 'string'; } exports.isString = isString; function isSymbol(arg) { return typeof arg === 'symbol'; } exports.isSymbol = isSymbol; function isUndefined(arg) { return arg === void 0; } exports.isUndefined = isUndefined; function isRegExp(re) { return isObject(re) && objectToString(re) === '[object RegExp]'; } exports.isRegExp = isRegExp; function isObject(arg) { return typeof arg === 'object' && arg !== null; } exports.isObject = isObject; function isDate(d) { return isObject(d) && objectToString(d) === '[object Date]'; } exports.isDate = isDate; function isError(e) { return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error); } exports.isError = isError; function isFunction(arg) { return typeof arg === 'function'; } exports.isFunction = isFunction; function isPrimitive(arg) { return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' || // ES6 symbol typeof arg === 'undefined'; } exports.isPrimitive = isPrimitive; exports.isBuffer = require('./support/isBuffer'); function objectToString(o) { return Object.prototype.toString.call(o); } function pad(n) { return n < 10 ? '0' + n.toString(10) : n.toString(10); } var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34 function timestamp() { var d = new Date(); var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); return [d.getDate(), months[d.getMonth()], time].join(' '); } // log is just a thin wrapper to console.log that prepends a timestamp exports.log = function() { console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); }; /** * Inherit the prototype methods from one constructor into another. * * The Function.prototype.inherits from lang.js rewritten as a standalone * function (not on Function.prototype). NOTE: If this file is to be loaded * during bootstrapping this function needs to be rewritten using some native * functions as prototype setup using normal JavaScript does not work as * expected during bootstrapping (see mirror.js in r114903). * * @param {function} ctor Constructor function which needs to inherit the * prototype. * @param {function} superCtor Constructor function to inherit prototype from. */ exports.inherits = require('inherits'); exports._extend = function(origin, add) { // Don't do anything if add isn't an object if (!add || !isObject(add)) return origin; var keys = Object.keys(add); var i = keys.length; while (i--) { origin[keys[i]] = add[keys[i]]; } return origin; }; function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./support/isBuffer":6,"_process":4,"inherits":5}]},{},[2]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
generators
Manual
Vanilla
Jumper
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Based on the provided JavaScript code and benchmark results, I will attempt to answer your question. However, I need more context or information about what you are trying to achieve. The provided code snippet appears to be related to testing and benchmarking web browsers, specifically Firefox 54. The benchmark results show four different test cases with varying execution rates per second. The "TestName" column indicates which test case is being run (Vanilla, Jumper, Manual, or generators). Without more context about what you want to accomplish with this code or the specific question you're trying to answer, I'll provide a general response. Is there something specific you'd like to know or achieve with this code? Are you trying to: 1. Optimize the performance of the `timestamp` function? 2. Analyze the benchmark results to understand which test case performs best? 3. Use the `_extend` function to modify object properties? Please provide more information about your goals, and I'll do my best to assist you!
Related benchmarks:
Reduce to array
Stack vs Queue
spread vs push set creation 2
fill vs push multiple
fill vs push multiple small
Comments
Confirm delete:
Do you really want to delete benchmark?