MCPcopy
hub / github.com/TheAlgorithms/JavaScript / ExampleIntervalTimer

Function ExampleIntervalTimer

Timing-Functions/IntervalTimer.js:65–90  ·  view source on GitHub ↗
(output = (v) => console.log(v))

Source from the content-addressed store, hash-verified

63 * @description Example usage
64 */
65const ExampleIntervalTimer = function (output = (v) => console.log(v)) {
66 /**
67 * Create am object with default settings.
68 * @type {IntervalTimer} Used to get timing information.
69 */
70 const timer = new IntervalTimer()
71 timer.startTimer()
72
73 // ... Initialization code ...
74 // I generally use it for timing tests in Jasmine JS.
75
76 /**
77 * Gets the runtime till this point.
78 * Can be subtracted from ElapsedTime to offset timing of initialization code.
79 */
80 const initOffset = timer.getRunTime()
81
82 // ... A test ...
83 // The time taken to run the test.
84 output(timer.getElapsedTime(initOffset))
85
86 /**
87 * Returns the elapsed time and resets the timer to 0.
88 */
89 output(timer.resetTimer())
90}
91
92export { IntervalTimer, ExampleIntervalTimer }

Callers

nothing calls this directly

Calls 6

startTimerMethod · 0.95
getRunTimeMethod · 0.95
getElapsedTimeMethod · 0.95
resetTimerMethod · 0.95
outputFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected