r/learnjavascript • u/bear007 • Oct 27 '20
Best way to measure execution time with Javascript
3
u/TheSpiffySpaceman Oct 28 '20 edited Oct 28 '20
obligatory "execution time for browser code isn't a good indicator of performance, doesn't represent user experience, doesn't account for IoC containers, don't forget about performance.now(), yatta yatta
1
10
u/Morphray Oct 28 '20
Does it bother anyone else that it’s not timerStart and timerEnd? Sorry these console method names fail code review.
5
u/drumstix42 Oct 28 '20
It's mainly because the parameter is a string to "name" the timer. You're starting a timer via the label. "Start" is just implied.
Personally I just use
performance.now()and subtract the 2 values.
5
u/subnub99 Oct 27 '20
I remember seeing Ben Awad doing this, before I was creating a date object and subtracting it from the current time when the function finished. Using console.time is so much better
1
5
u/drumstix42 Oct 28 '20
Check out: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
P.S. where is this from? Is this like a daily card homepage or something??