Javascript How fast your code is? HD
Suppose we have two code snippets that do the same thing. How to check which one is faster? Let we have an array of numbers. And we have to do mathematical evaluation for each item. There is more than one way to do it. One way is to use a map method and an arrow function. The other way is to use a for loop and a push method. So we have two code snippets for one task. Which one is faster? Let’s define the benchmark function. Function has one parameter: code snippet. In that function we will repeat code snippet execution multiple times. And we check how much time it requires. The less time period the faster the code snippet. OK. Let’s check it out. The snippet A with a map method. And the snippet B with a for loop. The snippet B has required less time. The for snippet is faster.
Похожие видео
Показать еще