Performance between index() and hashmap . get()

Asked

Viewed 54 times

0

I’m having a performance issue with my application and I’m thinking it might be the various .get() that I give, this way I’m considering transforming these hashmaps for arrays and use the indexOf() to do the searches, you think there is gain in performance using indexOf() instead of .get()?

1 answer

2


the get() of the map has complexity O(1) and the indexOf() of array has O(n) complexity, so you can’t even compare, so much the difference in performance, and switch to the array It will get a lot worse, unless the question is unclear and you want to do something else, or that hashmap in fact it is formed by numbers in sequence, there the array becomes natural.

If you have performance problems you need to figure out where it is, there’s no point speculating, just knowing exactly where the problem is that you can look for the best solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.