Conversation
|
It's taking longer because you are defining the array in each call. If the array is a constant, the array is actually faster. |
|
@harshkhandeparkar This doesnt affect much, array is still much slower: Also, in the source code we defining array in function, so I do this in the test |
|
Checking the first element by indexOf is also slower: |
|
I did a little more testing too. I found that using |
|
I used 10^9 operations here and also used a key in between the array (clz32) instead of at last. |
|
Further testing reveals how the time taken changes when the element to be searched changes:
|
Somehow, my initial test gave different results. The later tests are consistent with yours. Nice find! Although, changing to |
If you swap the order of the |
Why? |
Maybe gc or cache related? |
Hmm, perhaps. I tested them separately and found that includes still has the benefit of constant search time. and |
|
attaching the code as a file here and deleting the above snippets. |
Can confirm this is true, thanks a lot for your help! lets switch to |
984dd10 to
8bc05a5
Compare
speed up compile by using map instead of array
map is more than 30x faster