Q:

Write a JavaScript program to measure the time taken by a function to execute

0

Write a JavaScript program to measure the time taken by a function to execute.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const time_taken = callback => {
  const result = callback();
  return result;
};
console.log("Time taken: " + time_taken(() => Math.pow(2, 10))+" ms"); 
console.log("Time taken: " + time_taken(() => Math.sqrt(225))+" ms");
console.log("Time taken: " + time_taken(() => Math.sqrt((5 * 5) + (6 * 6)))+" ms");

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now