jeudi 24 novembre 2016

Why is a binary search over a sorted vector is slower than std::set find?

Here you can see the code, run it and see the times.

http://ift.tt/2fvZatN

I get similar results on my machine (using the same version of MSVC), the lookup in the vector is almost four times slower than in the std::set.

I would expect the sorted vector version to be faster, due to better locality of the data (more cache friendly). In the worse case, I would expect them to be similar, because they both perform a binary search, but I cannot understand why the std::set is much faster than the sorted vector version.

Thank you very much

Aucun commentaire:

Enregistrer un commentaire