http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58333

            Bug ID: 58333
           Summary: "performance" regression when using -std=c++0x
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mendola at gmail dot com

Created attachment 30753
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30753&action=edit
Preprocessed files (with and without -std=c++0x)

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)


I'm attaching the preprocessed file, using or not the -std=c++0x, what you can
see in the following test case that if compiled with -std=c++0x the
"benchmarked" piece of code runs 1.5 seconds slower (8.9 seconds vs 10.4
seconds).
If in the code the "chrono" call is removed then with or without -std=c++0x the
running time are the same.


#include <iostream>
#include <boost/chrono.hpp>
#include <sys/time.h>
#include <math.h>

int main() {
  cpu_set_t  myAffinityMask;
  CPU_ZERO( &myAffinityMask );
  CPU_SET(0, &myAffinityMask );
  sched_setaffinity(0, sizeof(myAffinityMask), &myAffinityMask);

  volatile float* myMemoryA = new float[(1<<24)];
  volatile float* myMemoryB = new float[(1<<24)];

  struct timeval myStart;
  struct timeval myStop;
  struct timeval myResult;

  gettimeofday(&myStart, 0);

  for (size_t i = 0; i < (1<<24); ++i) {
    myMemoryA[i] = i;
    myMemoryB[i] = i+1;
  }
  delete []myMemoryA;
  delete []myMemoryB;

  for (size_t j = 0; j < 100; ++j) {
    volatile float* myMemoryA = new float[(1<<24)];
    volatile float* myMemoryB = new float[(1<<24)];
    for (size_t i = 0; i < (1<<24); ++i) {
      myMemoryA[i] *= sqrtf(myMemoryB[i]);
    }
    delete []myMemoryA;
    delete []myMemoryB;
  }
  gettimeofday(&myStop, 0);

  timersub(&myStop,&myStart,&myResult);

  std::cout << "Time: " <<  myResult.tv_sec*1000 + myResult.tv_usec/1000.0 <<
std::endl;

  boost::chrono::time_point<boost::chrono::steady_clock> t1 =
boost::chrono::high_resolution_clock::now();
  std::cout << "t1: " << t1 << std::endl;
}

Reply via email to