perf-marks
Version:
The simplest and lightweight solution for User Timing API in Javascript.
1 lines • 3.48 kB
JavaScript
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).PerfMarks={})}(this,function(e){"use strict";function t(){return(f?performance:Date).now()}function o(e){s[e]=void 0,p[e]&&(p[e]=void 0),f&&(i||performance.clearMeasures(e),performance.clearMarks(e))}function a(r){var n;f&&(i&&u&&(n=new PerformanceObserver(function(e){p[r]=e.getEntries().find(function(e){return e.name===r}),n.disconnect()})).observe({entryTypes:["measure"]}),performance.mark(r)),s[r]=t()}function c(e,r){try{var n=s[e];return f?(r||performance.mark(e+"-end"),performance.measure(e,e,r||e+"-end"),i?p[e]||(n?{duration:t()-n,startTime:n,entryType:"measure",name:e}:{}):performance.getEntriesByName(e).pop()||{}):n?{duration:t()-n,startTime:n,entryType:"measure",name:e}:{}}catch(e){return{}}finally{o(e),o(r||e+"-end")}}function r(e){return f&&!i&&performance.getEntriesByType(e)||[]}var i="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),f="undefined"!=typeof performance&&void 0!==performance.now&&"function"==typeof performance.mark&&"function"==typeof performance.measure&&("function"==typeof performance.clearMarks||"function"==typeof performance.clearMeasures),u="undefined"!=typeof PerformanceObserver&&void 0!==PerformanceObserver.prototype&&"function"==typeof PerformanceObserver.prototype.constructor,s={},p={};function n(e,c,i,f){return new(i=i||Promise)(function(n,r){function t(e){try{a(f.next(e))}catch(e){r(e)}}function o(e){try{a(f.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?n(e.value):((r=e.value)instanceof i?r:new i(function(e){e(r)})).then(t,o)}a((f=f.apply(e,c||[])).next())})}function l(n,t){var o,a,c,i={label:0,sent:function(){if(1&c[0])throw c[1];return c[1]},trys:[],ops:[]},e={next:r(0),throw:r(1),return:r(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function r(r){return function(e){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;i;)try{if(o=1,a&&(c=2&r[0]?a.return:r[0]?a.throw||((c=a.return)&&c.call(a),0):a.next)&&!(c=c.call(a,r[1])).done)return c;switch(a=0,(r=c?[2&r[0],c.value]:r)[0]){case 0:case 1:c=r;break;case 4:return i.label++,{value:r[1],done:!1};case 5:i.label++,a=r[1],r=[0];continue;case 7:r=i.ops.pop(),i.trys.pop();continue;default:if(!(c=0<(c=i.trys).length&&c[c.length-1])&&(6===r[0]||2===r[0])){i=0;continue}if(3===r[0]&&(!c||r[1]>c[0]&&r[1]<c[3])){i.label=r[1];break}if(6===r[0]&&i.label<c[1]){i.label=c[1],c=r;break}if(c&&i.label<c[2]){i.label=c[2],i.ops.push(r);break}c[2]&&i.ops.pop(),i.trys.pop();continue}r=t.call(n,i)}catch(e){r=[6,e],a=0}finally{o=c=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,e])}}}e.clear=o,e.clearAll=function(){s={},p={},f&&(i||performance.clearMeasures(),performance.clearMarks())},e.end=c,e.getEntriesByType=r,e.getNavigationMarker=function(){return r("navigation").pop()||{}},e.isNodeJSEnv=i,e.isPerformanceObservableSupported=u,e.isUserTimingAPISupported=f,e.profiler=function(t,o){return n(void 0,void 0,void 0,function(){var r,n;return l(this,function(e){switch(e.label){case 0:a(o),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,t()];case 2:return r=e.sent(),n=c(o),[2,r?Object.assign({},{data:r,mark:n}):{mark:n}];case 3:throw n=e.sent(),c(o),n;case 4:return[2]}})})},e.start=a,Object.defineProperty(e,"__esModule",{value:!0})});