I was in the middle of learning about custom Vulkan allocation and desired to implement my own allocator, which ended up turning into a custom container for C++. I based my container off of std::vector, and was expecting—as I am not proficient in programming—it to be very inefficient. But when I compared the two, my container was seemingly much faster than std::vector. I do realize I potentially could use the reserve() member function of std::vector, but I am too lazy to properly use it. So am I accurately measuring the performance, or am I implementing something wrong? If this is not the place for this question, or I am asking it wrong, please tell me how to properly ask it, because this is my first time using any sort of public answer site thing. Note that I forked this from my personal account, due to this being my school account.
Can I rely on the comparison of my implementation of std::vector and std::vector itself
std::vector typically uses dynamic resizing strategies when its capacity is reached, which might involve allocating new memory, copying elements, and deallocating the old memory. Since your test case involves a small number of elements and doesn’t reach the capacity limit, this overhead is probably not affecting the performance of std::vector.
However… it’s worth noting that this behavior is part of the reason why
std::vector is more versatile and efficient for larger and more unpredictable data sets.
I would recommend you to test against a wider range of scenarios to see how it performs in more realistic use cases.