{"version":3,"file":"timer.mjs","names":[],"sources":["../../../src/domain/performance/timer.ts"],"sourcesContent":["import type { RelativeTime, Duration, TimeStamp } from '@datadog/js-core/time'\nimport { elapsed, timeStampNow, relativeNow } from '@datadog/js-core/time'\n\nexport function createTimer() {\n  let duration: Duration | undefined\n  let startTime: TimeStamp | undefined\n  let highPrecisionStartTime: RelativeTime | undefined\n\n  return {\n    startTimer(this: void) {\n      // timeStampNow uses Date.now() internally, which is not high precision, but this is what is\n      // used for other events, so we use it here as well.\n      startTime = timeStampNow()\n\n      // relativeNow uses performance.now() which is higher precision than Date.now(), so we use for\n      // the duration\n      highPrecisionStartTime = relativeNow()\n    },\n\n    stopTimer(this: void) {\n      duration = elapsed(highPrecisionStartTime!, relativeNow())\n    },\n\n    getDuration(this: void) {\n      return duration\n    },\n\n    getStartTime(this: void) {\n      return startTime\n    },\n  }\n}\n"],"mappings":";;AAGA,SAAgB,cAAc;CAC5B,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,OAAO;EACL,aAAuB;GAGrB,YAAY,aAAa;GAIzB,yBAAyB,YAAY;EACvC;EAEA,YAAsB;GACpB,WAAW,QAAQ,wBAAyB,YAAY,CAAC;EAC3D;EAEA,cAAwB;GACtB,OAAO;EACT;EAEA,eAAyB;GACvB,OAAO;EACT;CACF;AACF"}