mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Have the module-cost benchmark page self identify and output into a text box to make copy-pasting the data out easier.
29 lines
693 B
JavaScript
29 lines
693 B
JavaScript
export async function measure(name, fn) {
|
|
let module
|
|
let loadDuration
|
|
{
|
|
const start = performance.now()
|
|
module = await fn()
|
|
const end = performance.now()
|
|
loadDuration = end - start
|
|
}
|
|
|
|
let files
|
|
let executeDuration
|
|
{
|
|
const execute = module.execute
|
|
const start = performance.now()
|
|
files = execute()
|
|
const end = performance.now()
|
|
executeDuration = end - start
|
|
}
|
|
|
|
const result = { name, loadDuration, executeDuration, files }
|
|
|
|
return result
|
|
}
|
|
|
|
export function format(result) {
|
|
return `${result.name}: Load duration: ${result.loadDuration.toFixed(2)}ms, Execution duration: ${result.executeDuration.toFixed(2)}ms, Files: ${result.files}`
|
|
}
|