|
Boost : |
Subject: [boost] [boost.chrono] Slow down process (if specifing c++11)
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2013-08-26 09:54:39
Hi have tried the following code compiling it with gcc 4.6.3,
with four combinations:
1) -O3
2) -O3 (commeting out the chrono call)
3) -O3 -std=c++0x
4) -O3 -std=c++0x (commenting out the chrono call)
and I'm obtaining the following runtime values:
1) 8921 ms
2) 8915 ms
3) 9400 ms
4) 8933 ms
as you can see the combination: "c++11 and chrono call" slows down the entire
process. I have tried the same with gcc 4.8.1 and all times are more or less
the same.
At this point I'm not sure if it's a problem of chrono with gcc 4.6.3 or
simply an issue of 4.6.3 disappeared in 4.8.1 series.
Regards
Gaetano Mendola
Here the code I have used:
#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;
boost::chrono::time_point<boost::chrono::steady_clock> t1 = boost::chrono::high_resolution_clock::now();
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;
std::cout << "t1: " << t1 << std::endl;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk