divinepet/ft_containers-unit-test

Bug: huge difference in time of `erase` vector method

Opened this issue · 1 comments

I am getting a huge different in time between my implementation of vector::erase and the std one.
Screenshot 2022-12-10 at 20 50 42

My implementation is already pretty lean:

iterator erase(iterator position)
{
    this->_alloc.destroy(&(*position));
    for (iterator it = position; it < (this->end() - 1); ++it)
        this->_alloc.construct(&(*(it)), *(it + 1));
    this->_alloc.destroy(this->_data + this->_size - 1);
    this->_size--;
    return position;
}

What seems suspicious to me is that I'm pratically getting the same times no matter how much I tweak my code.
Also, I'm not getting such a huge difference in my own tests:
Screenshot 2022-12-10 at 23 05 13

What seems especially suspicious is std time in your tester.

Although I suffer the same problem with erase(value), I think it's not a bug, it depends on how we implement the end() method: https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.1/stl__vector_8h-source.html#l00350