Hacker News new | ask | show | jobs
by striking 3772 days ago
That revision tests the best case (looking for string "a") while the revision I picked tests the worst case (looking for string "xxx", which doesn't exist). I picked it just because it came up first in Google search. Testing in my browser (Safari 9.0.1, Mac OS X 10.10.5) still gives a 54x improvement to Object indexing, though.

Perhaps getting the first value in an array is faster than indexing an Object in your browser.

The point is, if the thing doesn't exist, this part of the program will be thousands of times slower, and will get slower as the list of roles grows. Meanwhile, the hash map will not.

1 comments

Thanks for the explanation!