Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
Measuring await time in Node

Let's say I have a function in Node

const my_function = async () => {
  await sub_function_1();
  await sub_function_2();
  await sub_function_3();
}

I could profile how long it takes my_function to run with:

let t0 = new Date()
await my_function()
let t1 = new Date()
let elapsed_ms = t1 - t0

But that wouldn't show me how long each of the sub_functions took to run. Similarly, I would add profiling code around each of the sub_functions, but that wouldn't show me which one of the sub-sub functions took the longest amount of time to run.

Is there a way, for a given function call, the gather all of the awaited functions underneath that call, along with how long each took to resolve?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

what about a wrapper function which take a array of functions and runs them sequentially?

//simulating a lengthy request
const sub_function = (time) => {return new Promise((res,rej) => setTimeout( () => res(true),time  ) )}

const new_list = [
    {handler:sub_function(90), alias:"sub_function_1"},
    {handler:sub_function(150), alias:"sub_function_2"},
    {handler:sub_function(350), alias:"sub_function_3"},

]

const calculate_max_time = async list =>{
    const time_passed = []
    for (const func of list) {

        const time = Date.now()
        await func.handler
        const time2 = Date.now()
        time_passed.push({alias:func.alias, value:time2 - time})
    }
    const max_time = time_passed.reduce( (max,func) => max.value > func.value ? max : func)
    console.log(max_time)
}

calculate_max_time(new_list)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda