W
W
WarriorKodeK2018-02-10 19:01:20
JavaScript
WarriorKodeK, 2018-02-10 19:01:20

How to check code execution speed?

Hello. Recently, I have been thinking more and more about the speed of my code.
Perhaps you can tell me some utilities for this or what do you use when measuring the speed of your code?
Thanks for the replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-02-10
@WarriorKodeK

If you are interested in a specific node, you can use performance.now :

var t0 = performance.now();
doSomething();
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");

For asynchronous tasks:
var t0 = performance.now();
var t1;
doSomething().then(result => {
  t1 = performance.now();
  console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question