Skip to content

Commit d14f7ec

Browse files
committed
refactor(kit,nuxt): use performance.now to measure time
1 parent ffab26b commit d14f7ec

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/kit/src/module/define.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (definition: Mo
7171

7272
// Call setup
7373
const key = `nuxt:module:${uniqueKey || (Math.round(Math.random() * 10000))}`
74-
const mark = performance.mark(key)
74+
const start = performance.now()
7575
const res = await module.setup?.call(null as any, _options, nuxt) ?? {}
76-
const perf = performance.measure(key, mark.name)
77-
const setupTime = Math.round((perf.duration * 100)) / 100
76+
const perf = performance.now() - start
77+
const setupTime = Math.round((perf * 100)) / 100
7878

7979
// Measure setup time
8080
if (setupTime > 5000 && uniqueKey !== '@nuxt/telemetry') {

packages/nuxt/src/core/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
6262

6363
async function processTemplate (template: ResolvedNuxtTemplate) {
6464
const fullPath = template.dst || resolve(nuxt.options.buildDir, template.filename!)
65-
const mark = performance.mark(fullPath)
65+
const start = performance.now()
6666
const oldContents = nuxt.vfs[fullPath]
6767
const contents = await compileTemplate(template, templateContext).catch((e) => {
6868
logger.error(`Could not compile template \`${template.filename}\`.`)
@@ -85,8 +85,8 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
8585
changedTemplates.push(template)
8686
}
8787

88-
const perf = performance.measure(fullPath, mark.name)
89-
const setupTime = Math.round((perf.duration * 100)) / 100
88+
const perf = performance.now() - start
89+
const setupTime = Math.round((perf * 100)) / 100
9090

9191
if (nuxt.options.debug || setupTime > 500) {
9292
logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`)

0 commit comments

Comments
 (0)