Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!