- Notifications
You must be signed in to change notification settings - Fork666
feat: speed up compile by map#713
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:develop
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
harshkhandeparkar commentedSep 3, 2021
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:
|
harshkhandeparkar commentedSep 3, 2021
I did a little more testing too. I found that using
|
harshkhandeparkar commentedSep 3, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I used 10^9 operations here and also used a key in between the array (clz32) instead of at last. |
harshkhandeparkar commentedSep 3, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Further testing reveals how the time taken changes when the element to be searched changes:
|
harshkhandeparkar commentedSep 3, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 |
harshkhandeparkar commentedSep 3, 2021
Why? |
Maybe gc or cache related? |
harshkhandeparkar commentedSep 3, 2021
Hmm, perhaps. I tested them separately and found that includes still has the benefit of constant search time.
and
|
harshkhandeparkar commentedSep 3, 2021
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
to8bc05a5
Compare
speed up compile by using map instead of array
map is more than 30x faster