UNPKG

molstar

Version:

A comprehensive macromolecular library.

73 lines 2.79 kB
"use strict"; /* * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * Adapted from LiteMol * Copyright (c) 2016 - now David Sehnal, licensed under Apache 2.0, See LICENSE file for more info. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PerformanceMonitor = void 0; var now_1 = require("../mol-util/now"); var PerformanceMonitor = /** @class */ (function () { function PerformanceMonitor() { this.starts = new Map(); this.ends = new Map(); } PerformanceMonitor.currentTime = function () { return (0, now_1.now)(); }; PerformanceMonitor.prototype.start = function (name) { this.starts.set(name, (0, now_1.now)()); }; PerformanceMonitor.prototype.end = function (name) { this.ends.set(name, (0, now_1.now)()); }; PerformanceMonitor.format = function (t) { if (isNaN(t)) return 'n/a'; var h = Math.floor(t / (60 * 60 * 1000)), m = Math.floor(t / (60 * 1000) % 60), s = Math.floor(t / 1000 % 60); var ms = Math.floor(t % 1000).toString(); while (ms.length < 3) ms = '0' + ms; if (h > 0) return h + "h" + m + "m" + s + "." + ms + "s"; if (m > 0) return m + "m" + s + "." + ms + "s"; if (s > 0) return s + "." + ms + "s"; return t.toFixed(0) + "ms"; }; PerformanceMonitor.prototype.formatTime = function (name) { return PerformanceMonitor.format(this.time(name)); }; PerformanceMonitor.prototype.formatTimeSum = function () { var names = []; for (var _i = 0; _i < arguments.length; _i++) { names[_i] = arguments[_i]; } return PerformanceMonitor.format(this.timeSum.apply(this, names)); }; /** Returns the time in milliseconds and removes them from the cache. */ PerformanceMonitor.prototype.time = function (name) { var start = this.starts.get(name), end = this.ends.get(name); this.starts.delete(name); this.ends.delete(name); return end - start; }; PerformanceMonitor.prototype.timeSum = function () { var _this = this; var names = []; for (var _i = 0; _i < arguments.length; _i++) { names[_i] = arguments[_i]; } var t = 0; for (var _a = 0, _b = names.map(function (n) { return _this.ends.get(n) - _this.starts.get(n); }); _a < _b.length; _a++) { var m = _b[_a]; t += m; } return t; }; return PerformanceMonitor; }()); exports.PerformanceMonitor = PerformanceMonitor; //# sourceMappingURL=performance-monitor.js.map