You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code works, but there's a potential performance problem in it.
25
+
O código funciona, porém existe um potencial problema de performance aqui.
26
26
27
-
The method`result.includes(str)`internally walks the array `result`and compares each element against`str`to find the match.
27
+
O método`result.includes(str)`internamente percorre o array `result`e compara cada elemento com`str`para achar um que combine.
28
28
29
-
So if there are `100`elements in`result`and no one matches`str`, then it will walk the whole `result`and do exactly `100`comparisons. And if`result`is large, like`10000`, then there would be `10000`comparisons.
29
+
Então se tiver `100`elementos em`result`e nenhum combine com`str`, então ele vai percorrer `result`inteiro e fazer exatamente `100`comparações. E se`result`for muito maior, como`10000`, então terá `10000`comparações.
30
30
31
-
That's not a problem by itself, because JavaScript engines are very fast, so walk `10000`array is a matter of microseconds.
31
+
Isso não é um problema tão preocupante porque as engines do JavaScript são muito rápidas, então percorrer um array de `10000`itens dura questões de microsegundos.
32
32
33
-
But we do such test for each element of `arr`, in the `for` loop.
33
+
Porém, nós estamos fazendo estes teste para cada elemento em `arr` no laço de repetição `for`.
34
34
35
-
So if`arr.length`is`10000`we'll have something like`10000*10000` = 100 millions of comparisons. That's a lot.
35
+
Então se`arr.length`for`10000`vamos ter algo como:`10000*10000` = 100 milhões de comparações. Isso é muito.
36
36
37
-
So the solution is only good for small arrays.
37
+
Então, essa solução é somente boa para arrays pequenas.
38
38
39
-
Further in the chapter<info:map-set-weakmap-weakset>we'll see how to optimize it.
39
+
Mais adiante no capítulo<info:map-set-weakmap-weakset>vamos ver como otimizar isso.
0 commit comments