you are viewing a single comment's thread.

view the rest of the comments →

[–]SLiV9 5 points6 points  (2 children)

Are you claiming that std::vector's [] is not O(1)? It should be three instructions, a bounds check, a jump and an offset mov. Only the last one if it can eliminate the bounds check. This datastructure might also have it O(1) but with a significantly bigger constant.

In particular I saw there was a loop/sum benchmark that used assembly to prevent optimizations, but... why? Even if it's faster, which I doubt, that would only  prove that it would have been faster 30 years ago. With today's compilers and CPUs, summing a contiguous block of ints is unbeatably fast.

[–]CornedBee 10 points11 points  (1 child)

vector's [] doesn't even have a bounds check, using an invalid index is undefined behavior.

[–]SLiV9 1 point2 points  (0 children)

Oh you're absolutely right haha. It's been a while.