From d14f7ec46089d332fa337eec0e59ef8988380b05 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 2 Jul 2024 12:12:56 +0100 Subject: [PATCH] refactor(kit,nuxt): use `performance.now` to measure time --- packages/kit/src/module/define.ts | 6 +++--- packages/nuxt/src/core/app.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/kit/src/module/define.ts b/packages/kit/src/module/define.ts index ff2a56d2d4..adde3a32fc 100644 --- a/packages/kit/src/module/define.ts +++ b/packages/kit/src/module/define.ts @@ -71,10 +71,10 @@ export function defineNuxtModule (definition: Mo // Call setup const key = `nuxt:module:${uniqueKey || (Math.round(Math.random() * 10000))}` - const mark = performance.mark(key) + const start = performance.now() const res = await module.setup?.call(null as any, _options, nuxt) ?? {} - const perf = performance.measure(key, mark.name) - const setupTime = Math.round((perf.duration * 100)) / 100 + const perf = performance.now() - start + const setupTime = Math.round((perf * 100)) / 100 // Measure setup time if (setupTime > 5000 && uniqueKey !== '@nuxt/telemetry') { diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index 4bc7da1e91..a6bb8c6e99 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -62,7 +62,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?: async function processTemplate (template: ResolvedNuxtTemplate) { const fullPath = template.dst || resolve(nuxt.options.buildDir, template.filename!) - const mark = performance.mark(fullPath) + const start = performance.now() const oldContents = nuxt.vfs[fullPath] const contents = await compileTemplate(template, templateContext).catch((e) => { logger.error(`Could not compile template \`${template.filename}\`.`) @@ -85,8 +85,8 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?: changedTemplates.push(template) } - const perf = performance.measure(fullPath, mark.name) - const setupTime = Math.round((perf.duration * 100)) / 100 + const perf = performance.now() - start + const setupTime = Math.round((perf * 100)) / 100 if (nuxt.options.debug || setupTime > 500) { logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`)