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.

Reply via email to