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

* [Bug libstdc++/100133] std::copy extremely slow for random access iterator
  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 ` hewillk at gmail dot com
  2021-04-18 17:22 ` hewillk at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2021-04-18  8:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100133

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
And the libstdc++‘s std::copy is also 8.9 times slower than the equivalent
std::tranfrom:

#include <vector>
#include <list>
#include <algorithm>

const std::vector<int> v(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 transform_from_vector(benchmark::State& state)
{
  for (auto _ : state) {
    std::vector<int> to(v.size());
    std::transform(
      v.begin(), v.end(), 
      to.begin(),
      [](int x) { return x; }
    );
  }
}
BENCHMARK(transform_from_vector);

you can see the benchmark here:
https://quick-bench.com/q/yuGf3npWpeU2EQhzzGud-aYNlNE. If using libc++,
std::copy is 2.2 times faster than std::transform as expected, see
https://quick-bench.com/q/3_V0EaU2jxnx4kSjWdarq7FOSh0.

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

* [Bug libstdc++/100133] std::copy extremely slow for random access iterator
  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
  3 siblings, 0 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2021-04-18 17:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100133

--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
After actually executing the same code on my local and remote servers, I did
not produce such a result. In both cases, std::copy achieved the expected
high-efficiency performance, so I think this should only be Quick C++ Benchmark
Own question, thank you for your time

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

* [Bug libstdc++/100133] std::copy extremely slow for random access iterator
  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
  3 siblings, 0 replies; 5+ messages in thread
From: hewillk at gmail dot com @ 2021-04-18 17:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100133

康桓瑋 <hewillk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to 康桓瑋 from comment #2)
> After actually executing the same code on my local and remote servers, I did
> not produce such a result. In both cases, std::copy achieved the expected
> high-efficiency performance, so I think this should only be Quick C++
> Benchmark
> Own question, thank you for your time

Close.

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

* [Bug libstdc++/100133] std::copy extremely slow for random access iterator
  2021-04-18  7:55 [Bug libstdc++/100133] New: std::copy extremely slow for random access iterator hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-18 17:28 ` hewillk at gmail dot com
@ 2021-04-18 19:03 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-18 19:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100133

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This should be RESOLVED INVALID not RESOLVED FIXED, because nothing needed to
be fixed.

^ 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).