public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100133] New: std::copy extremely slow for random access iterator
@ 2021-04-18  7:55 hewillk at gmail dot com
  2021-04-18  8:09 ` [Bug libstdc++/100133] " hewillk at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2021-04-18  7:55 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-18 19:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-18  7:55 [Bug libstdc++/100133] New: std::copy extremely slow for random access iterator hewillk at gmail dot com
2021-04-18  8:09 ` [Bug libstdc++/100133] " hewillk at gmail dot com
2021-04-18 17:22 ` hewillk at gmail dot com
2021-04-18 17:28 ` hewillk at gmail dot com
2021-04-18 19:03 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).