Skip to content

Instantly share code, notes, and snippets.

@anvaka
Created March 15, 2014 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anvaka/9561845 to your computer and use it in GitHub Desktop.
Save anvaka/9561845 to your computer and use it in GitHub Desktop.
requirebin sketch
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var totalPropertiesOnObjectWithProto = 0;
var totalPropertiesOnObjectWithoutProto = 0;
var hasPrototype = {};
addStuff(hasPrototype);
var noPrototype = Object.create(null);
addStuff(noPrototype);
suite.add('Run on object with prototype', function() {
var count = 0;
for (var k in hasPrototype) {
if (hasPrototype.hasOwnProperty(k)) count += 1;
}
totalPropertiesOnObjectWithProto = count;
}).add('Run on object without prototype', function () {
var count = 0;
for (var k in noPrototype) {
count += 1;
}
totalPropertiesOnObjectWithoutProto = count;
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('properties on object with prototype', totalPropertiesOnObjectWithProto);
console.log('properties on object without prototype', totalPropertiesOnObjectWithoutProto);
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
// run async
.run({ 'async': true });
function addStuff(target) {
for (var i = 0; i < 1000; ++i) {
target['prop' + i] = i;
}
}
function addStuff(e){for(var n=0;1e3>n;++n)e["prop"+n]=n}require=function e(n,t,r){function o(u,c){if(!t[u]){if(!n[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw Error("Cannot find module '"+u+"'")}var a=t[u]={exports:{}};n[u][0].call(a.exports,function(e){var t=n[u][1][e];return o(t?t:e)},a,a.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;r.length>u;u++)o(r[u]);return o}({1:[function(e,n){var t=n.exports={};t.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(n){var t=[];return window.addEventListener("message",function(e){var n=e.source;if((n===window||null===n)&&"process-tick"===e.data&&(e.stopPropagation(),t.length>0)){var r=t.shift();r()}},!0),function(e){t.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),t.title="browser",t.browser=!0,t.env={},t.argv=[],t.binding=function(){throw Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(){throw Error("process.chdir is not supported")}},{}],iFi3G2:[function(e,n,t){(function(r,o){(function(i,u){"use strict";function c(e,n,t){var r=this;return null==r||r.constructor!=c?new c(e,n,t):(C(e,"Object")?t=e:C(e,"Function")?(t=n,n=e):C(n,"Object")?(t=n,n=null,r.name=e):r.name=e,q(r,t),r.id||(r.id=++vn),null==r.fn&&(r.fn=n),r.stats=N(r.stats),r.times=N(r.times),u)}function s(e){var n=this;return null==n||n.constructor!=s?new s(e):(n.benchmark=e,hn(n),u)}function a(e){var n=this;return null==n||n.constructor!=a?new a(e):e instanceof a?e:D(n,{timeStamp:+new Date},"string"==typeof e?{type:e}:e)}function l(e,n){var t=this;return null==t||t.constructor!=l?new l(e,n):(C(e,"Object")?n=e:t.name=e,q(t,n),u)}function f(){for(var e,n=-1,t=arguments.length,r=h.call(this),o=r.length;t>++n;)if(e=arguments[n],C(e,"Array"))for(var i=0,u=e.length;u>i;i++,o++)i in e&&(r[o]=e[i]);else r[o++]=e;return r}function p(e,n,t){for(var r=e+n,o=t?t.length:0,i=e-1,u=e+o,c=this,s=Array(n),a=h.call(c,r);r>++i;)i in c&&(s[i-e]=c[i],delete c[i]);for(i=e-1;u>++i;)c[i]=t[i-e];for(e=i--,u=Zn(0,(c.length>>>0)-n+o);u>++i;)i-e in a?c[i]=a[i-e]:i in c&&delete c[i];for(n=n>o?n-o:0;n--;)i=u+n,i in c&&delete c[i];return c.length=u,s}function m(){var e,n,t=-1,r=Object(this),o=r.length>>>0,i=Jn(o/2);if(o>1)for(;i>++t;)e=o-t-1,n=e in r?r[e]:qn,t in r?r[e]=r[t]:delete r[e],n!=qn?r[t]=n:delete r[t];return r}function d(){return p.call(this,0,1)[0]}function h(e,n){var t=-1,r=Object(this),o=r.length>>>0,i=[];for(e=y(e),e=0>e?Zn(o+e,0):Qn(e,o),e--,n=null==n?o:y(n),n=0>n?Zn(o+n,0):Qn(n,o);++t,n>++e;)e in r&&(i[t]=r[e]);return i}function g(e,n){var t=Object(this),r=t.length>>>0;return e=y(e),e=0>e?Zn(r+e,0):Qn(e,r),n=1==arguments.length?r-e:Qn(Zn(y(n),0),r-e),p.call(t,e,n,h.call(arguments,2))}function y(e){return e=+e,0!==e&&isFinite(e)?e-e%1:e||0}function b(){var e=Object(this);return p.call(e,0,0,arguments),e.length}function v(e,n){return function(){e.apply(n,arguments)}}function $(){return $=function(e,n){var t,r=wn?define.amd:c,o=qn+"createFunction";return I((wn?"define.amd.":"Benchmark.")+o+"=function("+e+"){"+n+"}"),t=r[o],delete r[o],t},$=Wn.browser&&($("",'return"'+qn+'"')||A)()==qn?$:Function,$.apply(null,arguments)}function w(e,n){e._timerId=setTimeout(n,1e3*e.delay)}function j(e){In.appendChild(e),In.innerHTML=""}function O(){var e,n,t=!0,r=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"];return function(r,o){function i(){this.valueOf=0}i.prototype.valueOf=0;for(o in new i)r+="valueOf"==o?1:0;for(o in arguments)"0"==o&&(t=!1);n=2==r,e=!r}(0),O=function(o,i,c){c||(c={});var s=o;o=Object(o);var a,l,f,p,m=!s,d=c.which,h="all"==d,g=-1,y=o,b=o.length,$=h||"own"==d,w={},j=C(o,"Function"),O=c.bind;if(O!==u&&(i=v(i,O)),h&&Wn.getAllKeys)for(g=0,f=kn(o),b=f.length;b>g&&(l=f[g],i(o[l],l,o)!==!1);g++);else{for(l in o)if(m=!(j&&"prototype"==l||n&&(G(w,l)||!(w[l]=!0))||!(!$||$&&G(o,l))||i(o[l],l,o)!==!1))break;if(!m&&(t&&T(o)||(Kn||Gn)&&C(o,"String")&&(y=Kn?o.split(""):o)))for(;b>++g&&!(m=i(y[g],g+"",o)===!1););if(!m&&e)for(a=o.constructor,p=a&&a.prototype&&a.prototype.constructor===a,g=0;7>g&&(l=r[g],p&&"constructor"==l||!G(o,l)||i(o[l],l,o)!==!1);g++);}return s},O.apply(null,arguments)}function k(e){return!G(e,"toString")&&(/^[\s(]*function[^(]*\(([^\s,)]+)/.exec(e)||0)[1]||""}function S(e){return X(e,function(e,n){return e+n})/e.length||0}function x(e,n){var t=n;return E(e)?t=e+"":Wn.decompilation&&(t=(/^[^{]+\{([\s\S]*)}\s*$/.exec(e)||0)[1]),t=(t||"").replace(/^\s+|\s+$/g,""),/^(?:\/\*+[\w|\W]*?\*\/|\/\/.*?[\n\r\u2028\u2029]|\s)*(["'])use strict\1;?$/.test(t)?"":t}function T(){return T=function(e){return"[object Arguments]"==Bn.call(e)},Rn&&(T=function(e){return G(e,"callee")&&!(Fn&&Fn.call(e,"callee"))}),T(arguments[0])}function C(e,n){return null!=e&&Bn.call(e)=="[object "+n+"]"}function _(e,n){var t=null!=e?typeof e[n]:"number";return!/^(?:boolean|number|string|undefined)$/.test(t)&&("object"==t?!!e[n]:!0)}function P(e){var n=!1;if(!e||"object"!=typeof e||Rn&&T(e))return n;var t=e.constructor;return!Wn.nodeClass&&"function"!=typeof e.toString&&"string"==typeof(e+"")||C(t,"Function")&&!(t instanceof t)?n:Wn.iteratesOwnFirst?(O(e,function(e,t){n=t}),n===!1||G(e,n)):(O(e,function(t,r){return n=!G(e,r),!1}),n===!1)}function E(e){return G(e,"toString")||C(e,"String")}function F(e){return function(){var n=[this];return n.push.apply(n,arguments),e.apply(null,n)}}function A(){}function B(e){try{var n=jn&&On(e)}catch(t){}return n||null}function I(e){var n=wn?define.amd:c,t=$n.createElement("script"),r=$n.getElementsByTagName("script")[0],o=r.parentNode,i=qn+"runScript",u="("+(wn?"define.amd.":"Benchmark.")+i+"||function(){})();";try{t.appendChild($n.createTextNode(u+e)),n[i]=function(){j(t)}}catch(s){o=o.cloneNode(!1),r=null,t.text=e}o.insertBefore(t,r),delete n[i]}function q(e,n){n=D({},e.constructor.options,n),e.options=R(n,function(n,t){null!=n&&(/^on[A-Z]/.test(t)?L(t.split(" "),function(t){e.on(t.slice(2).toLowerCase(),n)}):G(e,t)||(e[t]=N(n)))})}function M(){var e=this,n=e.benchmark,t=n._original;t.aborted?(e.teardown(),n.running=!1,yn(e)):++e.cycles<n.count?Wn.timeout?setTimeout(function(){n.compiled.call(e,Ln)},0):n.compiled.call(e,Ln):(Ln.stop(e),e.teardown(),w(n,function(){yn(e)}))}function N(e){function n(e){this.raw=e}function t(t,r){if(!t||t.constructor!=n)if(t===Object(t))$[$.length++]={key:r,parent:u,source:e};else try{u[r]=t}catch(o){}}function r(e){for(var t=qn;e[t]&&e[t].constructor!=n;)t+=1;return t}var o,i,u,c,s,a,l,f,p,m,d,h,g,y={value:e},b=0,v=[],$={length:0},w=[];do{if(l=y.key,m=y.parent,h=y.source,u=e=h?h[l]:y.value,o=i=s=!1,e===Object(e)){if(C(e.deepClone,"Function"))u=e.deepClone();else switch(c=e.constructor,Bn.call(e)){case"[object Array]":u=new c(e.length);break;case"[object Boolean]":u=new c(1==e);break;case"[object Date]":u=new c(+e);break;case"[object Object]":P(e)&&(u={});break;case"[object Number]":case"[object String]":u=new c(e);break;case"[object RegExp]":u=c(e.source,(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":""))}if(u&&u!=e&&(s=h&&Wn.descriptors&&Sn(h,l),!(o=s&&(s.get||s.set)))){if(a=Tn(e))p=r(e),e[p]&&(i=u=e[p].raw);else for(g=0,f=w.length;f>g;g++)if(y=w[g],y.object===e){i=u=y.clone;break}i||(a?(e[p]=new n(u),v.push({key:p,object:e})):w.push({clone:u,object:e}),O(e,t,{which:"all"}))}}m?o||s&&!(s.configurable&&s.enumerable&&s.writable)?("value"in s&&(s.value=u),An(m,l,s)):m[l]=u:d=u}while(y=$[b++]);for(b=0,f=v.length;f>b;b++)y=v[b],delete y.object[y.key];return d}function z(e,n,t){var r=e;e=Object(e);var o=n,i=-1,u=e.length,c=!(!e.snapshotItem||!(u=e.snapshotLength)),s=(Kn||Gn)&&C(e,"String"),a=c||s||"item"in e,l=e;if(u===u>>>0){if(a)if(n=function(e,n){return o.call(this,e,n,l)},s)e=e.split("");else for(e=[];u>++i;)e[i]=c?r.snapshotItem(i):r[i];L(e,n,t)}else R(e,n,t);return r}function D(e){var n=e;return delete arguments[0],L(arguments,function(e){O(e,function(e,t){n[t]=e})}),n}function W(e,n,t){var r;return"successful"==n?n=function(e){return e.cycles&&isFinite(e.hz)}:("fastest"==n||"slowest"==n)&&(r=W(e,"successful").sort(function(e,t){return e=e.stats,t=t.stats,(e.mean+e.moe>t.mean+t.moe?1:-1)*("fastest"==n?1:-1)}),r=W(r,function(e){return 0==r[0].compare(e)})),r||X(e,function(r,o,i){return n.call(t,o,i,e)?(r.push(o),r):r},[])}function L(e,n,t){var r=-1,o=(e=Object(e)).length>>>0;for(t!==u&&(n=v(n,t));o>++r&&!(r in e&&n(e[r],r,e)===!1););return e}function R(e,n,t){return O(e,n,{bind:t,which:"own"})}function K(e){return e=(e+"").split("."),e[0].replace(/(?=(?:\d{3})+$)(?!\b)/g,",")+(e[1]?"."+e[1]:"")}function G(){return G=function(e,n){var t=null!=e&&(e.constructor||Object).prototype;return!!t&&n in Object(e)&&!(n in t&&e[n]===t[n])},C(xn,"Function")?G=function(e,n){return null!=e&&xn.call(e,n)}:{}.__proto__==Object.prototype&&(G=function(e,n){var t=!1;return null!=e&&(e=Object(e),e.__proto__=[e.__proto__,e.__proto__=null,t=n in e][0]),t}),G.apply(this,arguments)}function H(e,n,t){var r=y(t),o=(e=Object(e)).length>>>0;for(r=(0>r?Zn(0,o+r):r)-1;o>++r;)if(r in e&&n===e[r])return r;return-1}function J(e,n){return R(n,function(n,t){e=e.replace(RegExp("#\\{"+t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")+"\\}","g"),n)}),e}function Z(e,n){function t(){var e,t=o(f);return t&&(f.on("complete",r),e=f.events.complete,e.splice(0,0,e.pop())),b[m]=C(f&&f[n],"Function")?f[n].apply(f,s):u,!t&&r()}function r(n){var c,s=f,l=o(s);if(l&&(s.off("complete",r),s.emit("complete")),g.type="cycle",g.target=s,c=a(g),y.onCycle.call(e,c),c.aborted||i()===!1)g.type="complete",y.onComplete.call(e,a(g));else if(f=p?e[0]:b[m],o(f))w(f,t);else{if(!l)return!0;for(;t(););}return n?(n.aborted=!0,u):!1}function o(e){var t=s[0]&&s[0].async;return Object(e).constructor==c&&"run"==n&&((null==t?e.options.async:t)&&Wn.timeout||e.defer)}function i(){var n=b.length;if(p){do++m>0&&d.call(e);while((n=e.length)&&!("0"in e))}else for(;n>++m&&!(m in b););return(p?n:n>m)?m:m=!1}var s,f,p,m=-1,g={currentTarget:e},y={onStart:A,onCycle:A,onComplete:A},b=U(e,function(e){return e});if(C(n,"String")?s=h.call(arguments,2):(y=D(y,n),n=y.name,s=C(s="args"in y?y.args:[],"Array")?s:[s],p=y.queued),i()!==!1)if(f=b[m],g.type="start",g.target=f,y.onStart.call(e,a(g)),e.aborted&&e.constructor==l&&"run"==n)g.type="cycle",y.onCycle.call(e,a(g)),g.type="complete",y.onComplete.call(e,a(g));else if(o(f))w(f,t);else for(;t(););return b}function Q(e,n,t){var r=[],o=(e=Object(e)).length,i=o===o>>>0;return t||(t=": "),z(e,function(e,n){r.push(i?e:n+t+e)}),r.join(n||",")}function U(e,n,t){return X(e,function(r,o,i){return r[i]=n.call(t,o,i,e),r},Array(Object(e).length>>>0))}function V(e,n){return U(e,function(e){return null==e?u:e[n]})}function X(e,n,t){var r=3>arguments.length;return L(e,function(o,i){t=r?(r=!1,o):n(t,o,i,e)}),t}function Y(){var e,n=this,t=Mn.resetSuite;return n.running&&(e=a("abort"),n.emit(e),(!e.cancelled||t)&&(Mn.abortSuite=!0,n.reset(),delete Mn.abortSuite,t||(n.aborted=!0,Z(n,"abort")))),n}function en(e,n,t){var r=this,o=c(e,n,t),i=a({type:"add",target:o});return r.emit(i),i.cancelled||r.push(o),r}function nn(e){var n=this,t=new n.constructor(D({},n.options,e));return R(n,function(e,n){G(t,n)||(t[n]=e&&C(e.clone,"Function")?e.clone():N(e))}),t}function tn(e){var n=this,t=new n.constructor;return t.push.apply(t,W(n,e)),t}function rn(){var e,n=this,t=Mn.abortSuite;return n.running&&!t?(Mn.resetSuite=!0,n.abort(),delete Mn.resetSuite):!n.aborted&&!n.running||(n.emit(e=a("reset")),e.cancelled)||(n.running=!1,t||Z(n,"reset")),n}function on(e){var n=this;return n.reset(),n.running=!0,e||(e={}),Z(n,{name:"run",args:e,queued:e.queued,onStart:function(e){n.emit(e)},onCycle:function(e){var t=e.target;t.error&&n.emit({type:"error",target:t}),n.emit(e),e.aborted=n.aborted},onComplete:function(e){n.running=!1,n.emit(e)}}),n}function un(e){var n,t=this,r=a(e),o=t.events,i=(arguments[0]=r,arguments);return r.currentTarget||(r.currentTarget=t),r.target||(r.target=t),delete r.result,o&&(n=G(o,r.type)&&o[r.type])&&L(n.slice(),function(e){return(r.result=e.apply(t,i))===!1&&(r.cancelled=!0),!r.aborted}),r.result}function cn(e){var n=this,t=n.events||(n.events={});return G(t,e)?t[e]:t[e]=[]}function sn(e,n){var t=this,r=t.events;return r&&z(e?e.split(" "):r,function(e,t){var o;"string"==typeof e&&(t=e,e=G(r,t)&&r[t]),e&&(n?(o=H(e,n),o>-1&&e.splice(o,1)):e.length=0)}),t}function an(e,n){var t=this,r=t.events||(t.events={});return L(e.split(" "),function(e){(G(r,e)?r[e]:r[e]=[]).push(n)}),t}function ln(){var e,n=this,t=Mn.reset;return n.running&&(e=a("abort"),n.emit(e),(!e.cancelled||t)&&(Mn.abort=!0,n.reset(),delete Mn.abort,Wn.timeout&&(clearTimeout(n._timerId),delete n._timerId),t||(n.aborted=!0,n.running=!1))),n}function fn(e){var n=this,t=new n.constructor(D({},n,e));return t.options=D({},n.options,e),R(n,function(e,n){G(t,n)||(t[n]=N(e))}),t}function pn(e){function n(e,n){return X(n,function(n,t){return n+(t>e?0:e>t?1:.5)},0)}function t(e,t){return X(e,function(e,r){return e+n(r,t)},0)}function r(e){return(e-a*l/2)/Vn(a*l*(a+l+1)/12)}var o,i,u=this,c=u.stats.sample,s=e.stats.sample,a=c.length,l=s.length,f=Zn(a,l),p=Qn(a,l),m=t(c,s),d=t(s,c),h=Qn(m,d);return u==e?0:a+l>30?(i=r(h),Hn(i)>1.96?i>0?-1:1:0):(o=5>f||3>p?0:Dn[f][p-3],o>=h?h==m?1:-1:0)}function mn(){var e,n,t=this,r=0,o={length:0},i={length:0};if(t.running&&!Mn.abort)Mn.reset=!0,t.abort(),delete Mn.reset;else{e={destination:t,source:D({},t.constructor.prototype,t.options)};do R(e.source,function(n,t){var r,u=e.destination,c=u[t];n&&"object"==typeof n?(C(n,"Array")?(C(c,"Array")||(r=c=[]),c.length!=n.length&&(r=c=c.slice(0,n.length),c.length=n.length)):c&&"object"==typeof c||(r=c={}),r&&(o[o.length++]={destination:u,key:t,value:c}),i[i.length++]={destination:c,source:n}):n===c||null==n||C(n,"Function")||(o[o.length++]={destination:u,key:t,value:n})});while(e=i[r++]);o.length&&(t.emit(n=a("reset")),!n.cancelled)&&L(o,function(e){e.destination[e.key]=e.value})}return t}function dn(){var e=this,n=e.error,t=e.hz,r=e.id,o=e.stats,i=o.sample.length,u=Wn.java?"+/-":"±",c=e.name||(isNaN(r)?r:"<Test #"+r+">");return c+=n?": "+Q(n):" x "+K(t.toFixed(100>t?2:0))+" ops/sec "+u+o.rme.toFixed(2)+"% ("+i+" run"+(1==i?"":"s")+" sampled)"}function hn(){function e(e){for(var n,t,r=30,o=1e3,i=Ln.ns,u=[];r--;){if("us"==e)if(o=1e6,i.stop)for(i.start();!(n=i.microseconds()););else if(i[Pn])o=1e3,n=Function("n","var r,s=n."+Pn+"();while(!(r=n."+Pn+"()-s)){};return r")(i);else for(t=i();!(n=i()-t););else if("ns"==e)if(o=1e9,i.nanoTime)for(t=i.nanoTime();!(n=i.nanoTime()-t););else{for(t=(t=i())[0]+t[1]/o;!(n=(n=i())[0]+n[1]/o-t););o=1}else for(t=new i;!(n=new i-t););if(!(n>0)){u.push(1/0);break}u.push(n)}return S(u)/o}function n(e){return J(e,o).replace(/\$/g,/\d+/.exec(qn))}var t,r=c.options,o={begin:"s$=new n$",end:"r$=(new n$-s$)/1e3",uid:qn},u=[{ns:Ln.ns,res:Zn(.0015,e("ms")),unit:"ms"}];hn=function(e){var o;e instanceof s&&(o=e,e=o.benchmark);var i=e._original,u=i.fn,c=o?k(u)||"deferred":"",a=E(u),l={setup:x(i.setup,n("m$.setup()")),fn:x(u,n("m$.fn("+c+")")),fnArg:c,teardown:x(i.teardown,n("m$.teardown()"))},f=i.count=e.count,p=Wn.decompilation||a,m=i.id,d=!(l.fn||a),h=i.name||("number"==typeof m?"<Test #"+m+">":m),g=Ln.ns,y=0;if(e.minTime=i.minTime||(i.minTime=i.options.minTime=r.minTime),t)try{g.nanoTime()}catch(b){g=Ln.ns=new t.Packages.nano}var v=i.compiled=$(n("t$"),J(n(o?'var d$=this,#{fnArg}=d$,m$=d$.benchmark._original,f$=m$.fn,su$=m$.setup,td$=m$.teardown;if(!d$.cycles){d$.fn=function(){var #{fnArg}=d$;if(typeof f$=="function"){try{#{fn}\n}catch(e$){f$(d$)}}else{#{fn}\n}};d$.teardown=function(){d$.cycles=0;if(typeof td$=="function"){try{#{teardown}\n}catch(e$){td$()}}else{#{teardown}\n}};if(typeof su$=="function"){try{#{setup}\n}catch(e$){su$()}}else{#{setup}\n};t$.start(d$);}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}"}'),l));try{if(d)throw Error('The test "'+h+'" is empty. This may be the result of dead code removal.');o||(i.count=1,v=(v.call(i,Ln)||{}).uid==qn&&v,i.count=f)}catch(b){v=null,e.error=b||Error(b+""),i.count=f}if(p&&!v&&!o&&!d){v=$(n("t$"),J(n((e.error&&!a?"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$}"),l));try{i.count=1,v.call(i,Ln),i.compiled=v,i.count=f,delete e.error}catch(b){i.count=f,e.error?v=null:(i.compiled=v,e.error=b||Error(b+""))}}return e.compiled=v,e.error||(y=v.call(o||i,Ln).elapsed),y},z($n&&$n.applets||[],function(e){return!(Ln.ns=t="nanoTime"in e&&e)});try{"number"==typeof Ln.ns.nanoTime()&&u.push({ns:Ln.ns,res:e("ns"),unit:"ns"})}catch(a){}try{(Ln.ns=new(i.chrome||i.chromium).Interval)&&u.push({ns:Ln.ns,res:e("us"),unit:"us"})}catch(a){}if((Ln.ns=Pn&&_n)&&u.push({ns:Ln.ns,res:e("us"),unit:"us"}),En&&"function"==typeof(Ln.ns=En.hrtime)&&u.push({ns:Ln.ns,res:e("ns"),unit:"ns"}),Cn&&"function"==typeof(Ln.ns=Cn.now)&&u.push({ns:Ln.ns,res:e("us"),unit:"us"}),Ln=X(u,function(e,n){return n.res<e.res?n:e}),"ns"!=Ln.unit&&t&&(t=j(t)),1/0==Ln.res)throw Error("Benchmark.js was unable to find a working timer.");return"ns"==Ln.unit?Ln.ns.nanoTime?D(o,{begin:"s$=n$.nanoTime()",end:"r$=(n$.nanoTime()-s$)/1e9"}):D(o,{begin:"s$=n$()",end:"r$=n$(s$);r$=r$[0]+(r$[1]/1e9)"}):"us"==Ln.unit&&(Ln.ns.stop?D(o,{begin:"s$=n$.start()",end:"r$=n$.microseconds()/1e6"}):Pn?D(o,{begin:"s$=n$."+Pn+"()",end:"r$=(n$."+Pn+"()-s$)/1e3"}):D(o,{begin:"s$=n$()",end:"r$=(n$()-s$)/1e6"})),Ln.start=$(n("o$"),n("var n$=this.ns,#{begin};o$.elapsed=0;o$.timeStamp=s$")),Ln.stop=$(n("o$"),n("var n$=this.ns,s$=o$.timeStamp,#{end};o$.elapsed=r$")),r.minTime||(r.minTime=Zn(Ln.res/2/.01,.05)),hn.apply(null,arguments)}function gn(e,n){function t(){a.push(e.clone({_original:e,events:{abort:[r],cycle:[r],error:[r],start:[r]}}))}function r(n){var t=this,r=n.type;e.running?"start"==r?t.count=e.initCount:("error"==r&&(e.error=t.error),"abort"==r?(e.abort(),e.emit("cycle")):(n.currentTarget=n.target=e,e.emit(n))):e.aborted&&(t.events.abort.length=0,t.abort())}function o(n){var r,o,i,f,p,m,d,h,g=n.target,y=e.aborted,b=+new Date,v=l.push(g.times.period),$=v>=s&&(u+=b-g.times.timeStamp)/1e3>e.maxTime,w=e.times,j=function(e,n){return e+Un(n-i,2)};(y||1/0==g.hz)&&($=!(v=l.length=a.length=0)),y||(i=S(l),h=X(l,j,0)/(v-1)||0,m=Vn(h),d=m/Vn(v),o=v-1,r=zn[Math.round(o)||1]||zn.infinity,f=d*r,p=100*(f/i)||0,D(e.stats,{deviation:m,mean:i,moe:f,rme:p,sem:d,variance:h}),$&&(e.initCount=c,e.running=!1,y=!0,w.elapsed=(b-w.timeStamp)/1e3),1/0!=e.hz&&(e.hz=1/i,w.cycle=i*e.count,w.period=i)),2>a.length&&!$&&t(),n.aborted=y}n||(n={});var i=n.async,u=0,c=e.initCount,s=e.minSamples,a=[],l=e.stats.sample;t(),Z(a,{name:"run",args:{async:i},queued:!0,onCycle:o,onComplete:function(){e.emit("complete")}})}function yn(e,n){n||(n={});var t;e instanceof s&&(t=e,e=e.benchmark);var r,o,i,u,c,l,f=n.async,p=e._original,m=e.count,d=e.times;e.running&&(o=++e.cycles,r=t?t.elapsed:hn(e),c=e.minTime,o>p.cycles&&(p.cycles=o),e.error&&(u=a("error"),u.message=e.error,e.emit(u),u.cancelled||e.abort())),e.running&&(p.times.cycle=d.cycle=r,l=p.times.period=d.period=r/m,p.hz=e.hz=1/l,p.initCount=e.initCount=m,e.running=c>r,e.running&&(r||null==(i=Nn[e.cycles])||(m=Jn(4e6/i)),e.count>=m&&(m+=Math.ceil((c-r)/l)),e.running=1/0!=m)),u=a("cycle"),e.emit(u),u.aborted&&e.abort(),e.running?(e.count=m,t?e.compiled.call(t,Ln):f?w(e,function(){yn(e,n)}):yn(e)):(Wn.browser&&I(qn+"=1;delete "+qn),e.emit("complete"))}function bn(e){var n=this,t=a("start");return n.running=!1,n.reset(),n.running=!0,n.count=n.initCount,n.times.timeStamp=+new Date,n.emit(t),t.cancelled||(e={async:(null==(e=e&&e.async)?n.async:e)&&Wn.timeout},n._original?n.defer?s(n):yn(n,e):gn(n,e)),n}var vn=0,$n=_(i,"document")&&document,wn="function"==typeof define&&"object"==typeof define.amd&&define.amd&&define,jn="object"==typeof t&&t&&("object"==typeof o&&o&&o==o.global&&(i=o),t),On="function"==typeof e&&e,kn=Object.getOwnPropertyNames,Sn=Object.getOwnPropertyDescriptor,xn={}.hasOwnProperty,Tn=Object.isExtensible||function(){return!0},Cn=B("microtime"),_n=_(i,"performance")&&performance,Pn=_n&&(_n.now&&"now"||_n.webkitNow&&"webkitNow"),En=_(i,"process")&&r,Fn={}.propertyIsEnumerable,An=Object.defineProperty,Bn={}.toString,In=$n&&$n.createElement("div"),qn="uid"+ +new Date,Mn={},Nn={1:4096,2:512,3:64,4:8,5:0},zn={1:12.706,2:4.303,3:3.182,4:2.776,5:2.571,6:2.447,7:2.365,8:2.306,9:2.262,10:2.228,11:2.201,12:2.179,13:2.16,14:2.145,15:2.131,16:2.12,17:2.11,18:2.101,19:2.093,20:2.086,21:2.08,22:2.074,23:2.069,24:2.064,25:2.06,26:2.056,27:2.052,28:2.048,29:2.045,30:2.042,infinity:1.96},Dn={5:[0,1,2],6:[1,2,3,5],7:[1,3,5,6,8],8:[2,4,6,8,10,13],9:[2,4,7,10,12,15,17],10:[3,5,8,11,14,17,20,23],11:[3,6,9,13,16,19,23,26,30],12:[4,7,11,14,18,22,26,29,33,37],13:[4,8,12,16,20,24,28,33,37,41,45],14:[5,9,13,17,22,26,31,36,40,45,50,55],15:[5,10,14,19,24,29,34,39,44,49,54,59,64],16:[6,11,15,21,26,31,37,42,47,53,59,64,70,75],17:[6,11,17,22,28,34,39,45,51,57,63,67,75,81,87],18:[7,12,18,24,30,36,42,48,55,61,67,74,80,86,93,99],19:[7,13,19,25,32,38,45,52,58,65,72,78,85,92,99,106,113],20:[8,14,20,27,34,41,48,55,62,69,76,83,90,98,105,112,119,127],21:[8,15,22,29,36,43,50,58,65,73,80,88,96,103,111,119,126,134,142],22:[9,16,23,30,38,45,53,61,69,77,85,93,101,109,117,125,133,141,150,158],23:[9,17,24,32,40,48,56,64,73,81,89,98,106,115,123,132,140,149,157,166,175],24:[10,17,25,33,42,50,59,67,76,85,94,102,111,120,129,138,147,156,165,174,183,192],25:[10,18,27,35,44,53,62,71,80,89,98,107,117,126,135,145,154,163,173,182,192,201,211],26:[11,19,28,37,46,55,64,74,83,93,102,112,122,132,141,151,161,171,181,191,200,210,220,230],27:[11,20,29,38,48,57,67,77,87,97,107,118,125,138,147,158,168,178,188,199,209,219,230,240,250],28:[12,21,30,40,50,60,70,80,90,101,111,122,132,143,154,164,175,186,196,207,218,228,239,250,261,272],29:[13,22,32,42,52,62,73,83,94,105,116,127,138,149,160,171,182,193,204,215,226,238,249,260,271,282,294],30:[13,23,33,43,54,65,76,87,98,109,120,131,143,154,166,177,189,200,212,223,235,247,258,270,282,293,305,317]},Wn={};(function(){Wn.air=C(i.runtime,"ScriptBridgingProxyObject"),Wn.argumentsClass=C(arguments,"Arguments"),Wn.browser=$n&&_(i,"navigator"),Wn.charByIndex="xx"=="x"[0]+Object("x")[0],Wn.charByOwnIndex=Wn.charByIndex&&G("x","0"),Wn.java=C(i.java,"JavaPackage"),Wn.timeout=_(i,"setTimeout")&&_(i,"clearTimeout");try{Wn.decompilation="1"===Function("return ([object Object])")()(0).x}catch(e){Wn.decompilation=!1}try{var n={};Wn.descriptors=(An(n,n,n),"value"in Sn(n,n))}catch(e){Wn.descriptors=!1}try{Wn.getAllKeys=/\bvalueOf\b/.test(kn(Object.prototype))}catch(e){Wn.getAllKeys=!1}Wn.iteratesOwnFirst=function(){function e(){this.x=1}var n=[];e.prototype={y:1};for(var t in new e)n.push(t);return"x"==n[0]}();try{Wn.nodeClass="[object Object]"!=Bn.call($n||0)}catch(e){Wn.nodeClass=!0}})();var Ln={ns:Date,start:null,stop:null},Rn=!Wn.argumentsClass,Kn=!Wn.charByIndex,Gn=!Wn.charByOwnIndex,Hn=Math.abs,Jn=Math.floor,Zn=Math.max,Qn=Math.min,Un=Math.pow,Vn=Math.sqrt;D(c,{options:{async:!1,defer:!1,delay:.005,id:u,initCount:1,maxTime:5,minSamples:5,minTime:0,name:u,onAbort:u,onComplete:u,onCycle:u,onError:u,onReset:u,onStart:u},platform:B("platform")||i.platform||{description:i.navigator&&navigator.userAgent||null,layout:null,product:null,name:null,manufacturer:null,os:null,prerelease:null,version:null,toString:function(){return this.description||""}},version:"1.0.0",support:Wn,deepClone:N,each:z,extend:D,filter:W,forEach:L,forOwn:R,formatNumber:K,hasKey:(G(c,""),G),indexOf:H,interpolate:J,invoke:Z,join:Q,map:U,pluck:V,reduce:X}),D(c.prototype,{count:0,cycles:0,hz:0,compiled:u,error:u,fn:u,aborted:!1,running:!1,setup:A,teardown:A,stats:{moe:0,rme:0,sem:0,deviation:0,mean:0,sample:[],variance:0},times:{cycle:0,elapsed:0,period:0,timeStamp:0},abort:ln,clone:fn,compare:pn,emit:un,listeners:cn,off:sn,on:an,reset:mn,run:bn,toString:dn}),D(s.prototype,{benchmark:null,cycles:0,elapsed:0,timeStamp:0,resolve:M}),D(a.prototype,{aborted:!1,cancelled:!1,currentTarget:u,result:u,target:u,timeStamp:0,type:""}),l.options={name:u},D(l.prototype,{length:0,aborted:!1,running:!1,forEach:F(L),indexOf:F(H),invoke:F(Z),join:[].join,map:F(U),pluck:F(V),pop:[].pop,push:[].push,sort:[].sort,reduce:F(X),abort:Y,add:en,clone:nn,emit:un,filter:tn,listeners:cn,off:sn,on:an,reset:rn,run:on,concat:f,reverse:m,shift:d,slice:h,splice:g,unshift:b}),D(c,{Deferred:s,Event:a,Suite:l}),"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return c}):jn?"object"==typeof n&&n&&n.exports==jn?(n.exports=c).Benchmark=c:jn.Benchmark=c:i.Benchmark=c,Wn.air&&hn({_original:{fn:A,count:1,options:{}}})})(this)}).call(this,e("/home/admin/browserify-cdn/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"/home/admin/browserify-cdn/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":1}],benchmark:[function(e,n){n.exports=e("iFi3G2")},{}]},{},[]);var Benchmark=require("benchmark"),suite=new Benchmark.Suite,totalPropertiesOnObjectWithProto=0,totalPropertiesOnObjectWithoutProto=0,hasPrototype={};addStuff(hasPrototype);var noPrototype=Object.create(null);addStuff(noPrototype),suite.add("Run on object with prototype",function(){var e=0;for(var n in hasPrototype)hasPrototype.hasOwnProperty(n)&&(e+=1);totalPropertiesOnObjectWithProto=e}).add("Run on object without prototype",function(){var e=0;for(var n in noPrototype)e+=1;totalPropertiesOnObjectWithoutProto=e}).on("cycle",function(e){console.log(e.target+"")}).on("complete",function(){console.log("properties on object with prototype",totalPropertiesOnObjectWithProto),console.log("properties on object without prototype",totalPropertiesOnObjectWithoutProto),console.log("Fastest is "+this.filter("fastest").pluck("name"))}).run({async:!0});
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"benchmark": "1.0.0"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment