Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ unordered_map string vs int key performance

Is there a significant difference in performance (if I'm doing random lookups), between using string and int keys? In my particular case, string keys are more convenient, but with a bit of difficulty, I could get a setup with int keys as well. I'm just wondering if it is worth the extra effort.

like image 813
user788171 Avatar asked Nov 15 '25 21:11

user788171


1 Answers

It is pretty clear that hashing and comparing strings is generally more expensive than hashing and comparing ints.

Whether this is of any practical significance to your particular program, we can't tell. You'll need to profile your program and find out for yourself.

My advice is to to code for clarity and ease of maintenance, then profile and only optimize the bottlenecks.

like image 78
NPE Avatar answered Nov 18 '25 12:11

NPE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!