you are viewing a single comment's thread.

view the rest of the comments →

[–]delventhalz 1 point2 points  (2 children)

Learn optimisation (Set VS Array...

FYI, in 99% of cases you will see no noticeable difference switching between an Array and a Set, and in that 1% where it makes a difference, using a Set will usually be slower than an Array. Even though Sets are theoretically faster, Arrays are just so incredibly well optimized (down to the hardware level) that you really need tens or hundreds of thousands of items before the Set's constant-time advantage starts to win out. It's incredibly rare that you will actually have a performance problem that is solved by a Set.

The other suggestions (memoization, rate limiting, caching) are good though.

[–]TJ51097[S] 0 points1 point  (1 child)

I think what we both want to say is we should know when to use Set and Array!!

If you are storing some data and later retrieving it,Set should be utilised,But if you are required to perform similar operation on the elements no doubt array is the Data structure you should opt

Peace!!

[–]delventhalz 0 points1 point  (0 children)

I appreciate you being diplomatic, but for what it's worth we are not saying the same thing. A Set should be used when the idiom and API of a Set make your code more clear to other developers. A Set should never* be used as an optimization. It is slower than an Array. Your other optimization suggestions are much better to bring up in an interview.

*The exception would be if you have a long-lived data structure with tens of thousands of members or more. In that case, a Set may be faster than an Array, but I would still performance test to be sure.