UNPKG

federer

Version:

Experiments in asynchronous federated learning and decentralized learning

30 lines 846 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Timer = void 0; const assert = require("assert"); /** Small helper class for measuring durations, in ms. */ class Timer { /** Time the execution time of a function */ static time(fn) { const timer = new Timer(); timer.start(); const result = fn(); const time = timer.ms(); return [time, result]; } start() { assert(this.startTime === undefined); this.startTime = new Date().getTime(); } isStarted() { return this.startTime !== undefined; } ms() { assert(this.startTime !== undefined); const time = new Date().getTime() - this.startTime; assert(time >= 0); return time; } } exports.Timer = Timer; //# sourceMappingURL=Timer.js.map