+ 7
If-statements, switch, HashMap, which one has the best performance?
I have 1000 samples, if I only want to put a key and return a value, which one is the best?
3 Respostas
+ 3
then use hash map its provides the feature key-value pair
for 1000 samples you required more if statements use loop with if statement is good
switch is also required same
+ 6
If you're still on this matter, I'd like to note that I think Mayur Chaudhari's answer was correct, you will need to use "if" inside a loop to evaluate entries in the hash map. I also found some resources related to "if" performance.
http://www.jstips.co/en/javascript/short-circuit-evaluation-in-js/
http://www.openjs.com/articles/syntax/short_circuit_operators.php
http://www.grauw.nl/blog/entry/510
+ 5
Just came across this on a search...
Talk about performance, imo "if" or "switch" doesn't make the cycles increment, unless you are evaluating complex expressions, but even if you do, it still won't go as far as loops, especially those loops that has (heavy) function calls inside.
I think the statements to execute inside the matching conditions matter more. The choice to use "switch" over "if" to me is more a matter of code readability.