57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
|
define(["require", "exports"], function (require, exports) {
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.FabricPerformance = void 0;
|
||
|
var now = function () {
|
||
|
return typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now();
|
||
|
};
|
||
|
var RESET_INTERVAL = 3 * 60 * 1000; // auto reset every 3 minutes
|
||
|
/**
|
||
|
* Performance helper class for measuring things.
|
||
|
*
|
||
|
* @public
|
||
|
* {@docCategory FabricPerformance}
|
||
|
*/
|
||
|
var FabricPerformance = exports.FabricPerformance = /** @class */ (function () {
|
||
|
function FabricPerformance() {
|
||
|
}
|
||
|
/**
|
||
|
* Measures execution time of the given syncronous function. If the same logic is executed multiple times,
|
||
|
* each individual measurement will be collected as well the overall numbers.
|
||
|
* @param name - The name of this measurement
|
||
|
* @param func - The logic to be measured for execution time
|
||
|
*/
|
||
|
FabricPerformance.measure = function (name, func) {
|
||
|
if (FabricPerformance._timeoutId) {
|
||
|
FabricPerformance.setPeriodicReset();
|
||
|
}
|
||
|
var start = now();
|
||
|
func();
|
||
|
var end = now();
|
||
|
var measurement = FabricPerformance.summary[name] || {
|
||
|
totalDuration: 0,
|
||
|
count: 0,
|
||
|
all: [],
|
||
|
};
|
||
|
var duration = end - start;
|
||
|
measurement.totalDuration += duration;
|
||
|
measurement.count++;
|
||
|
measurement.all.push({
|
||
|
duration: duration,
|
||
|
timeStamp: end,
|
||
|
});
|
||
|
FabricPerformance.summary[name] = measurement;
|
||
|
};
|
||
|
FabricPerformance.reset = function () {
|
||
|
FabricPerformance.summary = {};
|
||
|
clearTimeout(FabricPerformance._timeoutId);
|
||
|
FabricPerformance._timeoutId = NaN;
|
||
|
};
|
||
|
FabricPerformance.setPeriodicReset = function () {
|
||
|
FabricPerformance._timeoutId = setTimeout(function () { return FabricPerformance.reset(); }, RESET_INTERVAL);
|
||
|
};
|
||
|
FabricPerformance.summary = {};
|
||
|
return FabricPerformance;
|
||
|
}());
|
||
|
});
|
||
|
//# sourceMappingURL=FabricPerformance.js.map
|