-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: speed up compile by map #713
base: develop
Are you sure you want to change the base?
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