- Notifications
You must be signed in to change notification settings - Fork 666
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 our terms of service and privacy 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 commented Sep 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. |
wwwzbwcom commented Sep 3, 2021
@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 |
wwwzbwcom commented Sep 3, 2021
Checking the first element by indexOf is also slower: |
harshkhandeparkar commented Sep 3, 2021
I did a little more testing too. I found that using |
harshkhandeparkar commented Sep 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 commented Sep 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 commented Sep 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 |
wwwzbwcom commented Sep 3, 2021
If you swap the order of the |
harshkhandeparkar commented Sep 3, 2021
Why? |
wwwzbwcom commented Sep 3, 2021
Maybe gc or cache related? |
harshkhandeparkar commented Sep 3, 2021
Hmm, perhaps. I tested them separately and found that includes still has the benefit of constant search time. and |
harshkhandeparkar commented Sep 3, 2021
attaching the code as a file here and deleting the above snippets. |
wwwzbwcom commented Sep 3, 2021
Can confirm this is true, thanks a lot for your help! lets switch to |
984dd10 to 8bc05a5Compare
speed up compile by using map instead of array
map is more than 30x faster