timit
Version:
Measure JavaScript function execution time
2 lines • 3.62 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.timit=e():t.timit=e()}(this,(function(){return(()=>{"use strict";var t={980:(t,e,n)=>{function r(t){let e=parseInt(t);return e>0?e:void 0}function o(t){return"Object"===Object.prototype.toString.call(t).slice(8,-1)}function i(t,...e){return e.reduce(((t,e)=>e(t)),t)}function a(t,e=0){const n=10**e;return Math.round(t*n)/n}n.d(e,{default:()=>y});const s=globalThis.process&&globalThis.process.hrtime,c=s?globalThis.process.hrtime.bigint.bind(globalThis.process.hrtime):globalThis.performance.now.bind(globalThis.performance),u=s?t=>parseInt(t)/1e6:t=>t;const p=function(t,e,n,r){return e.map((e=>t.map((t=>function(t,e=5,n){return Array.from({length:e}).map((()=>function(t,e=1){const n=c();for(;e--;)t();return u(c()-n)}(t,n)))}(t.bind(null,...e),n,r)))))};class f{constructor(t){this.option=Object.assign({funcs:[],argsList:[[]],repeat:5,numbers:1,output:h,digits:3},t)}time(...t){const e=i(t,l,(n=this.option,t=>{let e=Object.entries(t).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=n),t)),{});return Object.assign(Object.create(null),n,e)}),m,d);var n;const{funcs:r,argsList:o,repeat:a,numbers:s,output:c}=e,u=p(r,o,a,s),f=[g,b];return"function"==typeof c&&f.push(c),i({data:u,option:e},...f)}}function l(t){let e=t[0];if("object"==typeof e&&!Array.isArray(e))return e;let n=Array.isArray(e)?1:t.findIndex((t=>"function"!=typeof t));-1===n&&(n=t.length);const r=t.slice(0,n).flat(),o=t.slice(n);var i;o.length<3&&(function(t){return parseInt(t)===t}(i=o[0])&&i>0)&&o.unshift(void 0);const[a,s,c]=o;return{funcs:r.length?r:void 0,argsList:a,repeat:s,numbers:c}}function m({funcs:t,argsList:e,repeat:n,numbers:o,output:i,digits:a}){return{funcs:t?[].concat(t):[],argsList:[].concat(e).map((t=>[].concat(t))),repeat:r(n),numbers:r(o),digits:parseInt(a),output:i}}function d(t){const{funcs:e,digits:n}=t;if(!e.length||!e.every((t=>"function"==typeof t)))throw new TypeError("The param funcs is required a array of functions!");if(isNaN(n))throw new TypeError("The param digits is required int number!");return t}function g(t){const e=t.data;return{stat:{average:e.map((t=>t.map((t=>t.reduce(((t,e)=>t+e))/t.length)))),min:e.map((t=>t.map((t=>Math.min(...t))))),max:e.map((t=>t.map((t=>Math.max(...t)))))},...t}}function b(t){const{data:e,stat:n,option:{digits:r}}=t;return{data:e.map((t=>t.map((t=>t.map((t=>a(t,r))))))),stat:Object.entries(n).reduce(((t,[e,n])=>(t[e]=n.map((t=>t.map((t=>a(t,r))))),t)),Object.create(null)),option:t.option}}function h({data:t,stat:e,option:n}){const r=n.funcs.map(((t,e)=>t.name||`(anonymous${e})`)),o=n.argsList.map((t=>JSON.stringify(t).slice(1,-1))),i=t.map(((t,n)=>{const i=Object.assign(Object.create(null),{"(arguments)":o[n]});return r.reduce(((t,r,o)=>(t[r]=e.average[n][o],t)),i)}));if(t.length>1)return console.table(i),i;const a=t[0],s=a[0].map(((t,e)=>r.reduce(((t,n,r)=>(t[n]=a[r][e],t)),Object.create(null))));if(s.length>1){const t=i[0];delete t["(arguments)"],s.average=t}return console.table(s),s}function y(t){if(new.target){if(!o(t))throw new TypeError("option required Object type!");return new f(t)}return y.__instance||(y.__instance=new f),y.__instance.time(...arguments)}}},e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.exports}return n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n(980)})().default}));
//# sourceMappingURL=timit.js.map