UNPKG

@stdlib/bench-harness

Version:
20 lines (19 loc) 18.9 kB
"use strict";var n=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var K=n(function($i,Y){"use strict";Y.exports=setTimeout});var U=n(function(ea,z){"use strict";z.exports=clearTimeout});var Q=n(function(ra,J){"use strict";var Nr=K(),Br=U();function Cr(){var e,r;if(this._skip)return this.comment("SKIP "+this.name),this.end();if(!this._benchmark)return this.comment("TODO "+this.name),this.end();e=this,this._running=!0,r=Nr(t,this.timeout),this.once("end",i),this.emit("prerun"),this._benchmark(this),this.emit("run");function t(){e.fail("benchmark timed out after "+e.timeout+"ms")}function i(){Br(r)}}J.exports=Cr});var $=n(function(ta,Z){"use strict";function Dr(){this._exited||this._ended||(this._exited=!0,this.fail("benchmark exited without ending"),this._running||this.end())}Z.exports=Dr});var re=n(function(ia,ee){"use strict";function Vr(){return this._ended}ee.exports=Vr});var ae=n(function(aa,ie){"use strict";var te=require("@stdlib/assert-has-own-property");function jr(e,r){var t,i;t={id:this._count,ok:e,skip:r.skip,todo:r.todo,name:r.message||"(unnamed assert)",operator:r.operator},te(r,"actual")&&(t.actual=r.actual),te(r,"expected")&&(t.expected=r.expected),e||(t.error=r.error||new Error(this.name),i=new Error("not implemented")),this._count+=1,this.emit("result",t)}ie.exports=jr});var oe=n(function(na,se){"use strict";var ne=require("@stdlib/string-base-trim"),Fr=require("@stdlib/string-base-replace"),Hr=require("@stdlib/regexp-eol").REGEXP,Lr=/^#\s*/;function Gr(e){var r,t;for(e=ne(e),r=e.split(Hr),t=0;t<r.length;t++)e=ne(r[t]),e=Fr(e,Lr,""),this.emit("result",e)}se.exports=Gr});var le=n(function(sa,ue){"use strict";function Wr(e,r){this._assert(!0,{message:r,operator:"skip",skip:!0})}ue.exports=Wr});var fe=n(function(oa,ce){"use strict";function Xr(e,r){this._assert(!!e,{message:r,operator:"todo",todo:!0})}ce.exports=Xr});var me=n(function(ua,ve){"use strict";function Yr(e){this._assert(!1,{message:e,operator:"fail"})}ve.exports=Yr});var he=n(function(la,pe){"use strict";function Kr(e){this._assert(!0,{message:e,operator:"pass"})}pe.exports=Kr});var qe=n(function(ca,de){"use strict";function zr(e,r){this._assert(!!e,{message:r||"should be truthy",operator:"ok",expected:!0,actual:e})}de.exports=zr});var be=n(function(fa,ge){"use strict";function Ur(e,r){this._assert(!e,{message:r||"should be falsy",operator:"notOk",expected:!1,actual:e})}ge.exports=Ur});var xe=n(function(va,we){"use strict";function Jr(e,r,t){this._assert(e===r,{message:t||"should be equal",operator:"equal",expected:r,actual:e})}we.exports=Jr});var _e=n(function(ma,Ee){"use strict";function Qr(e,r,t){this._assert(e!==r,{message:t||"should not be equal",operator:"notEqual",expected:r,actual:e})}Ee.exports=Qr});var ye=n(function(pa,ke){"use strict";function Zr(e,r,t){this.comment("actual: "+e+". expected: "+r+". msg: "+t+".")}ke.exports=Zr});var Se=n(function(ha,Te){"use strict";function $r(e,r,t){this.comment("actual: "+e+". expected: "+r+". msg: "+t+".")}Te.exports=$r});var R=n(function(da,Oe){"use strict";function et(e){setTimeout(e,0)}Oe.exports=et});var Re=n(function(qa,Pe){"use strict";var rt=R();function tt(){var e=this;this._ended?this.fail(".end() called more than once"):rt(r),this._ended=!0,this._running=!1;function r(){e.emit("end")}}Pe.exports=tt});var A=n(function(ga,Ae){"use strict";var Ie=require("events").EventEmitter,it=require("@stdlib/utils-inherit"),I=require("@stdlib/utils-define-property"),v=require("@stdlib/utils-define-nonenumerable-read-only-property"),at=require("@stdlib/time-tic"),nt=require("@stdlib/time-toc"),st=Q(),ot=$(),ut=re(),lt=ae(),ct=oe(),ft=le(),vt=fe(),mt=me(),pt=he(),ht=qe(),dt=be(),qt=xe(),gt=_e(),bt=ye(),wt=Se(),xt=Re();function m(e,r,t){var i,a,s,o;if(!(this instanceof m))return new m(e,r,t);return s=this,i=!1,a=!1,Ie.call(this),v(this,"_benchmark",t),v(this,"_skip",r.skip),I(this,"_ended",{configurable:!1,enumerable:!1,writable:!0,value:!1}),I(this,"_running",{configurable:!1,enumerable:!1,writable:!0,value:!1}),I(this,"_exited",{configurable:!1,enumerable:!1,writable:!0,value:!1}),I(this,"_count",{configurable:!1,enumerable:!1,writable:!0,value:0}),v(this,"name",e),v(this,"tic",u),v(this,"toc",c),v(this,"iterations",r.iterations),v(this,"timeout",r.timeout),this;function u(){i?s.fail(".tic() called more than once"):(s.emit("tic"),i=!0,o=at())}function c(){var l,f,h,E;if(i===!1)return s.fail(".toc() called before .tic()");if(l=nt(o),a)return s.fail(".toc() called more than once");a=!0,s.emit("toc"),f=l[0]+l[1]/1e9,h=s.iterations/f,E={ok:!0,operator:"result",iterations:s.iterations,elapsed:f,rate:h},s.emit("result",E)}}it(m,Ie);v(m.prototype,"run",st);v(m.prototype,"exit",ot);v(m.prototype,"ended",ut);v(m.prototype,"_assert",lt);v(m.prototype,"comment",ct);v(m.prototype,"skip",ft);v(m.prototype,"todo",vt);v(m.prototype,"fail",mt);v(m.prototype,"pass",pt);v(m.prototype,"ok",ht);v(m.prototype,"notOk",dt);v(m.prototype,"equal",qt);v(m.prototype,"notEqual",gt);v(m.prototype,"deepEqual",bt);v(m.prototype,"notDeepEqual",wt);v(m.prototype,"end",xt);Ae.exports=m});var Be=n(function(ba,Ne){"use strict";var Et=require("@stdlib/string-base-replace"),Me=require("@stdlib/assert-has-own-property"),_t=require("@stdlib/regexp-eol").REGEXP,kt=/\s+/g;function yt(e,r){var t,i,a,s,o,u,c,l,f;if(l="",e.ok||(l+="not "),l+="ok "+r,e.name&&(l+=" "+Et(e.name.toString(),kt," ")),e.skip?l+=" # SKIP":e.todo&&(l+=" # TODO"),l+="\n",e.ok)return l;if(o=" ",l+=o+"---\n",l+=o+"operator: "+e.operator+"\n",(Me(e,"actual")||Me(e,"expected"))&&(a=e.expected,s=e.actual,s!==s&&a!==a))throw new Error("unexpected error.");if(e.at&&(l+=o+"at: "+e.at+"\n"),e.actual&&(t=e.actual.stack),e.error&&(i=e.error.stack),t?u=t:u=i,u)for(c=u.toString().split(_t),l+=o+"stack: |-\n",f=0;f<c.length;f++)l+=o+" "+c[f]+"\n";return l+=o+"...\n",l}Ne.exports=yt});var De=n(function(wa,Ce){"use strict";var y=" ",Tt=y+"---\n",St=y+"...\n";function Ot(e){var r=Tt;return r+=y+"iterations: "+e.iterations+"\n",r+=y+"elapsed: "+e.elapsed+"\n",r+=y+"rate: "+e.rate+"\n",r+=St,r}Ce.exports=Ot});var je=n(function(xa,Ve){"use strict";var Pt=require("@stdlib/assert-is-string").isPrimitive,Rt=Be(),It=De();function At(e){var r=this;this._benchmarks.push(e),e.once("prerun",t),e.on("result",i),this.emit("_push",e);function t(){r._stream.write("# "+e.name+"\n")}function i(a){if(Pt(a))return r._stream.write("# "+a+"\n");if(a.operator==="result")return a=It(a),r._stream.write(a);r.total+=1,a.ok?(a.skip?r.skip+=1:a.todo&&(r.todo+=1),r.pass+=1):a.todo?(r.pass+=1,r.todo+=1):r.fail+=1,a=Rt(a,r.total),r._stream.write(a)}}Ve.exports=At});var He=n(function(Ea,Fe){"use strict";var Mt=require("@stdlib/streams-node-transform"),Nt=require("@stdlib/assert-is-string").isPrimitive,Bt=R(),Ct="TAP version 13";function Dt(e){var r,t,i,a;return i=this,arguments.length?t=e:t={},r=new Mt(t),t.objectMode?(a=0,this.on("_push",c),this.on("done",l)):(r.write(Ct+"\n"),this._stream.pipe(r)),this.on("_run",u),r;function s(){Bt(o)}function o(){var f=i._benchmarks.shift();if(f)return f.run(),f.ended()?s():f.once("end",s);i._running=!1,i.emit("done")}function u(){if(!i._running)return i._running=!0,s()}function c(f){var h=a;a+=1,f.once("prerun",E),f.on("result",g),f.on("end",d);function E(){var p={type:"benchmark",name:f.name,id:h};r.write(p)}function g(p){Nt(p)?p={benchmark:h,type:"comment",name:p}:p.operator==="result"?(p.benchmark=h,p.type="result"):(p.benchmark=h,p.type="assert"),r.write(p)}function d(){r.write({benchmark:h,type:"end"})}}function l(){r.destroy()}}Fe.exports=Dt});var Ge=n(function(_a,Le){"use strict";function Vt(){this.emit("_run")}Le.exports=Vt});var Xe=n(function(ka,We){"use strict";function jt(){this._benchmarks.length=0}We.exports=jt});var Ke=n(function(ya,Ye){"use strict";function Ft(){var e=this;if(this._closed)return;this._closed=!0,this._benchmarks.length?(this.clear(),this._stream.write("# WARNING: harness closed before completion.\n")):(this._stream.write("#\n"),this._stream.write("1.."+this.total+"\n"),this._stream.write("# total "+this.total+"\n"),this._stream.write("# pass "+this.pass+"\n"),this.fail&&this._stream.write("# fail "+this.fail+"\n"),this.skip&&this._stream.write("# skip "+this.skip+"\n"),this.todo&&this._stream.write("# todo "+this.todo+"\n"),this.fail||this._stream.write("#\n# ok\n")),this._stream.once("close",r),this._stream.destroy();function r(){e.emit("close")}}Ye.exports=Ft});var Ue=n(function(Ta,ze){"use strict";function Ht(){var e,r;for(r=0;r<this._benchmarks.length;r++)this._benchmarks[r].exit();e=this,this.clear(),this._stream.once("close",t),this._stream.destroy();function t(){e.emit("close")}}ze.exports=Ht});var Ze=n(function(Sa,Qe){"use strict";var Je=require("events").EventEmitter,Lt=require("@stdlib/utils-inherit"),q=require("@stdlib/utils-define-property"),Gt=require("@stdlib/streams-node-transform"),Wt=je(),Xt=He(),Yt=Ge(),Kt=Xe(),zt=Ke(),Ut=Ue();function w(){return this instanceof w?(Je.call(this),q(this,"_benchmarks",{value:[],configurable:!1,writable:!1,enumerable:!1}),q(this,"_stream",{value:new Gt,configurable:!1,writable:!1,enumerable:!1}),q(this,"_closed",{value:!1,configurable:!1,writable:!0,enumerable:!1}),q(this,"_running",{value:!1,configurable:!1,writable:!0,enumerable:!1}),q(this,"total",{value:0,configurable:!1,writable:!0,enumerable:!0}),q(this,"fail",{value:0,configurable:!1,writable:!0,enumerable:!0}),q(this,"pass",{value:0,configurable:!1,writable:!0,enumerable:!0}),q(this,"skip",{value:0,configurable:!1,writable:!0,enumerable:!0}),q(this,"todo",{value:0,configurable:!1,writable:!0,enumerable:!0}),this):new w}Lt(w,Je);q(w.prototype,"push",{value:Wt,configurable:!1,writable:!1,enumerable:!1});q(w.prototype,"createStream",{value:Xt,configurable:!1,writable:!1,enumerable:!1});q(w.prototype,"run",{value:Yt,configurable:!1,writable:!1,enumerable:!1});q(w.prototype,"clear",{value:Kt,configurable:!1,writable:!1,enumerable:!1});q(w.prototype,"close",{value:zt,configurable:!1,writable:!1,enumerable:!1});q(w.prototype,"exit",{value:Ut,configurable:!1,writable:!1,enumerable:!1});Qe.exports=w});var $e=n(function(Oa,Jt){Jt.exports={skip:!1,iterations:null,repeats:3,timeout:3e5}});var rr=n(function(Pa,er){"use strict";var Qt=require("@stdlib/assert-is-plain-object"),M=require("@stdlib/assert-has-own-property"),Zt=require("@stdlib/assert-is-boolean").isPrimitive,$t=require("@stdlib/assert-is-null"),F=require("@stdlib/assert-is-positive-integer").isPrimitive,T=require("@stdlib/string-format");function ei(e,r){return Qt(r)?M(r,"skip")&&(e.skip=r.skip,!Zt(e.skip))?new TypeError(T("invalid option. `%s` option must be a boolean. Option: `%s`.","skip",e.skip)):M(r,"iterations")&&(e.iterations=r.iterations,!F(e.iterations)&&!$t(e.iterations))?new TypeError(T("invalid option. `%s` option must be either a positive integer or null. Option: `%s`.","iterations",e.iterations)):M(r,"repeats")&&(e.repeats=r.repeats,!F(e.repeats))?new TypeError(T("invalid option. `%s` option must be a positive integer. Option: `%s`.","repeats",e.repeats)):M(r,"timeout")&&(e.timeout=r.timeout,!F(e.timeout))?new TypeError(T("invalid option. `%s` option must be a positive integer. Option: `%s`.","timeout",e.timeout)):null:new TypeError(T("invalid argument. Options argument must be an object. Value: `%s`.",r))}er.exports=ei});var ir=n(function(Ra,tr){"use strict";var ri=require("@stdlib/assert-is-string").isPrimitive,ti=require("@stdlib/utils-copy"),ii=A();function ai(e,r,t,i){var a,s,o,u,c;o=0,u=0,s=ti(r),s.iterations=1,c=new ii(e,s,t),c.on("result",l),c.on("tic",f),c.on("toc",h),c.once("end",E),c.run();function l(g){!ri(g)&&!g.ok&&!g.todo&&(a=!0)}function f(){o+=1}function h(){u+=1}function E(){var g;return a?g=new Error("unexpected error. Benchmark failed."):(o!==1||u!==1)&&(g=new Error("unexpected error. Invalid benchmark.")),g?i(g):i()}}tr.exports=ai});var nr=n(function(Ia,ar){"use strict";var ni=require("@stdlib/assert-is-string").isPrimitive,si=require("@stdlib/utils-copy"),oi=A(),ui=.1,li=10,ci=1e10;function fi(e,r,t,i){var a,s;return s=0,a=si(r),a.iterations=li,o();function o(){var l=new oi(e,a,t);l.on("result",u),l.once("end",c),l.run()}function u(l){!ni(l)&&l.operator==="result"&&(s=l.elapsed)}function c(){if(s<ui&&a.iterations<ci)return a.iterations*=10,o();i(null,a.iterations)}}ar.exports=fi});var or=n(function(Aa,sr){"use strict";var vi=ir(),mi=nr();function pi(e,r,t,i){if(!t||r.skip)return r.repeats=1,i(e,r,t);vi(e,r,t,a);function a(o){if(o)return r.repeats=1,r.iterations=1,i(e,r,t);if(r.iterations)return i(e,r,t);mi(e,r,t,s)}function s(o,u){return o?(r.repeats=1,r.iterations=1,i(e,r,t)):(r.iterations=u,i(e,r,t))}}sr.exports=pi});var L=n(function(Ma,fr){"use strict";var H=require("@stdlib/utils-define-nonenumerable-read-only-property"),hi=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),ur=require("@stdlib/assert-is-string").isPrimitive,N=require("@stdlib/assert-is-function"),di=require("@stdlib/assert-is-boolean").isPrimitive,lr=require("@stdlib/assert-is-plain-object"),qi=require("@stdlib/assert-has-own-property"),k=require("@stdlib/string-format"),gi=require("@stdlib/utils-copy"),bi=A(),wi=Ze(),xi=R(),Ei=$e(),cr=rr(),_i=or();function ki(e,r){var t,i,a,s,o;if(s={},arguments.length===1)if(N(e))o=e;else if(lr(e))s=e;else throw new TypeError(k("invalid argument. Must provide either an options object or a function. Value: `%s`.",e));else if(arguments.length>1){if(!lr(e))throw new TypeError(k("invalid argument. First argument must be an object. Value: `%s`.",e));if(qi(e,"autoclose")&&(s.autoclose=e.autoclose,!di(s.autoclose)))throw new TypeError(k("invalid option. `%s` option must be a boolean. Option: `%s`.","autoclose",s.autoclose));if(o=r,!N(o))throw new TypeError(k("invalid argument. Second argument must be a function. Value: `%s`.",o))}i=new wi,s.autoclose&&i.once("done",h),o&&i.once("done",o),t=0,a=[];function u(d,p,D){var b,x,_;if(!ur(d))throw new TypeError(k("invalid argument. First argument must be a string. Value: `%s`.",d));if(b=gi(Ei),arguments.length===2){if(N(p))_=p;else if(x=cr(b,p),x)throw x}else if(arguments.length>2){if(x=cr(b,p),x)throw x;if(_=D,!N(_))throw new TypeError(k("invalid argument. Third argument must be a function. Value: `%s`.",_))}return a.push([d,b,_]),a.length===1&&xi(c),u}function c(){var d=-1;return p();function p(){var b;if(d+=1,d===a.length)return a.length=0,i.run();b=a[d],_i(b[0],b[1],b[2],D)}function D(b,x,_){var V,j;for(j=0;j<x.repeats;j++)V=new bi(b,x,_),V.on("result",l),i.push(V);return p()}}function l(d){!ur(d)&&!d.ok&&!d.todo&&(t=1)}function f(d){return arguments.length?i.createStream(d):i.createStream()}function h(){i.close()}function E(){i.exit()}function g(){return t}return H(u,"createStream",f),H(u,"close",h),H(u,"exit",E),hi(u,"exitCode",g),u}fr.exports=ki});var G=n(function(Na,vr){"use strict";var yi=require("process");vr.exports=yi});var hr=n(function(Ba,pr){"use strict";var mr=G(),Ti=mr&&typeof mr.exit=="function";pr.exports=Ti});var W=n(function(Ca,dr){"use strict";var Si=require("@stdlib/assert-is-browser"),Oi=hr(),Pi=!Si&&Oi;dr.exports=Pi});var gr=n(function(Da,qr){"use strict";function Ri(e){console.log(e)}qr.exports=Ri});var wr=n(function(Va,br){"use strict";var Ii=require("@stdlib/streams-node-transform"),Ai=require("@stdlib/string-from-code-point"),Mi=gr();function Ni(){var e,r;return e=new Ii({transform:t,flush:i}),r="",e;function t(a,s,o){var u,c;for(c=0;c<a.length;c++)u=Ai(a[c]),u==="\n"?i():r+=u;o()}function i(a){try{Mi(r)}catch(s){e.emit("error",s)}if(r="",a)return a()}}br.exports=Ni});var Sr=n(function(ja,Tr){"use strict";var xr=require("@stdlib/assert-is-function"),Bi=require("@stdlib/assert-is-boolean").isPrimitive,Er=require("@stdlib/assert-is-plain-object"),Ci=require("@stdlib/assert-is-node-writable-stream-like"),_r=require("@stdlib/assert-has-own-property"),S=require("@stdlib/string-format"),Di=require("@stdlib/utils-pick"),Vi=require("@stdlib/utils-omit"),kr=require("@stdlib/utils-noop"),ji=L(),Fi=wr(),Hi=W(),yr=G();function Li(){var e,r,t,i,a,s,o,u;if(arguments.length===0)i={},u=kr;else if(arguments.length===1)if(xr(arguments[0]))i={},u=arguments[0];else if(Er(arguments[0]))i=arguments[0],u=kr;else throw new TypeError(S("invalid argument. Must provide either an options object or a function. Value: `%s`.",arguments[0]));else{if(i=arguments[0],!Er(i))throw new TypeError(S("invalid argument. First argument must be an object. Value: `%s`.",i));if(u=arguments[1],!xr(u))throw new TypeError(S("invalid argument. Second argument must be a function. Value: `%s`.",u))}if(o={},_r(i,"autoclose")&&(o.autoclose=i.autoclose,!Bi(o.autoclose)))throw new TypeError(S("invalid option. `%s` option must be a boolean. Option: `%s`.","autoclose",o.autoclose));if(_r(i,"stream")&&(o.stream=i.stream,!Ci(o.stream)))throw new TypeError(S("invalid option. `%s` option must be a writable stream. Option: `%s`.","stream",o.stream));return e=0,s=Di(o,["autoclose"]),t=ji(s,c),s=Vi(i,["autoclose","stream"]),a=t.createStream(s),r=a.pipe(o.stream||Fi()),Hi&&(r.on("error",l),yr.on("exit",f)),t;function c(){return u()}function l(){e=1}function f(h){h===0&&(t.close(),yr.exit(e||t.exitCode))}}Tr.exports=Li});var Rr=n(function(Fa,Pr){"use strict";var Gi=W(),Wi=Sr(),B;function Or(e,r){var t,i;return B||(arguments.length>1?(t=e,i=r):(t={},i=e),t.autoclose=!Gi,B=Wi(t,i),Or.cached=!0,B)}Pr.exports=Or});var Mr=n(function(Ha,Ar){"use strict";var Xi=require("@stdlib/streams-node-transform"),X=require("@stdlib/utils-define-nonenumerable-read-only-property"),Yi=require("@stdlib/assert-is-function"),Ki=require("@stdlib/string-format"),zi=L(),C=Rr(),O=[];function Ir(){var e,r,t;for(e=O.length,t=0;t<e;t++)r=O.shift(),r()}function Ui(e){var r,t,i;return arguments.length?i=e:i={},C.cached?(t=C(),t.createStream(i)):(r=new Xi(i),i.stream=r,C(i,Ir),r)}function Ji(e){var r;if(!Yi(e))throw new TypeError(Ki("invalid argument. Must provide a function. Value: `%s`.",e));for(r=0;r<O.length;r++)if(e===O[r])throw new Error("invalid argument. Attempted to add duplicate listener.");O.push(e)}function P(e,r,t){var i=C(Ir);return arguments.length<2?i(e):arguments.length===2?i(e,r):i(e,r,t),P}X(P,"createHarness",zi);X(P,"createStream",Ui);X(P,"onFinish",Ji);Ar.exports=P});var Qi=Mr();module.exports=Qi; /** * @license Apache-2.0 * * Copyright (c) 2018 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //# sourceMappingURL=index.js.map