3 ms·
Virtual function calls can be expensive, just compare the out-of-the-box performance between std::sort (c++, no virtual calls) and qsort (c, "virtual call" via
by exDM69 9y ago
Virtual function calls can be expensive, just compare the out-of-the-box performance between std::sort (c++, no virtual calls) and qsort (c, "virtual call" via function pointer). This can make a 10x difference when sorting something trivial (e.g. integer array). std::sort will compile to a single instruction for the comparison, qsort will typically have to do a full virtual function call, not expensive by itself but still significantly worse than single integer comparison instruction.
- anarazel 9y agoThat's not a particularly meaningful comparison - qsort and std::sort aren't necessarily the same algorithm, moving elements is done differently, etc. So you're going to get very different results either way. If you wanted to compare you'd need to use an indirect function call with std::sort to compare - not hard to arrange...