Skip to content

Commit 8a7fd2d

Browse files
authored
fix: improve time measuring (#414)
1 parent e5862b6 commit 8a7fd2d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/task.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ export class Task extends EventTarget {
443443
// eslint-disable-next-line no-useless-call
444444
const fnResult = await this.#fn.call(this)
445445
let taskTime = this.#bench.opts.now() - taskStart
446+
446447
const overriddenDuration = getOverriddenDurationFromFnResult(fnResult)
447448
if (overriddenDuration !== undefined) {
448449
taskTime = overriddenDuration
@@ -454,11 +455,12 @@ export class Task extends EventTarget {
454455
const taskStart = this.#bench.opts.now()
455456
// eslint-disable-next-line no-useless-call
456457
const fnResult = this.#fn.call(this)
458+
let taskTime = this.#bench.opts.now() - taskStart
459+
457460
invariant(
458461
!isPromiseLike(fnResult),
459462
'task function must be sync when using `runSync()`'
460463
)
461-
let taskTime = this.#bench.opts.now() - taskStart
462464
const overriddenDuration = getOverriddenDurationFromFnResult(fnResult)
463465
if (overriddenDuration !== undefined) {
464466
taskTime = overriddenDuration

0 commit comments

Comments
 (0)