https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100133
Bug ID: 100133 Summary: std::copy extremely slow for random access iterator Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- HI, I found that libstdc++‘s std::copy is extremely slow for random access iterator. For the following example, if libc++'s std::copy is used, copy from std::vector will be 10 times faster than from std::list with -O3, but for libstdc++'s std::copy, copying from std::vector is twice as slow as std::list. #include <vector> #include <list> #include <algorithm> const std::vector<int> v(100, 42); const std::list<int> l(100, 42); static void copy_from_vector(benchmark::State& state) { for (auto _ : state) { std::vector<int> to(v.size()); std::copy( v.begin(), v.end(), to.begin() ); } } BENCHMARK(copy_from_vector); static void copy_from_list(benchmark::State& state) { for (auto _ : state) { std::vector<int> to(l.size()); std::copy( l.begin(), l.end(), to.begin() ); } } BENCHMARK(copy_from_list); you can see libc++‘s std::copy benchmark here: https://quick-bench.com/q/OPrNMQpJf6jKPBT5G-Uq-4U6XHc and libstdc++'s std::copy here: https://quick-bench.com/q/cuKCK_VE-KJgD3xA-ogXNCj9UCQ.