Results 1 to 3 of 3
I am trying to time a chunk of code. If I run it from the command line like:
Code:
taskset -c 0 ./conv
Conv Time: 0.014350082
I get a time ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-16-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 51
What is being cached?
I am trying to time a chunk of code. If I run it from the command line like:
I get a time of ~14ms but there is some variation. So, I put the command above into a script and ran to get an averageCode:taskset -c 0 ./conv Conv Time: 0.014350082
The output I get from running the script is:Code:taskset -c 0 ./conv taskset -c 0 ./conv . . . taskset -c 0 ./conv
What is causing the increased performance I see?Code:Conv Time: 0.014284663 Conv Time: 0.010995277 Conv Time: 0.008977601 Conv Time: 0.008802842 Conv Time: 0.009022121 Conv Time: 0.008894075 Conv Time: 0.008738924 Conv Time: 0.008423263 Conv Time: 0.008694661 Conv Time: 0.008902102
If the program is starting and exiting, what could be cached?
I also ran another version that I moved the program to a new core each time in the script.
That gave an output of:Code:taskset -c 0 ./conv taskset -c 1 ./conv . . . taskset -c 9 ./conv
Give that, something is helping the performance if I say on the same core.Code:Conv Time: 0.014503283 Conv Time: 0.013998719 Conv Time: 0.013912381 Conv Time: 0.014000417 Conv Time: 0.013930824 Conv Time: 0.013995235 Conv Time: 0.014705306 Conv Time: 0.013931455 Conv Time: 0.014027264 Conv Time: 0.014017024
Here is the code below
Code:// Use: // g++ -o conv -O3 conv.cpp -lrt // to compile #include <iostream> #include <cstdio> #include <sys/time.h> using namespace std; typedef struct { float real; float imag; } Complex_T; #define TAPS 228 #define SAMPS 341 int main(int argc, char **argv) { Complex_T y[TAPS+SAMPS],y2[TAPS+SAMPS],h[TAPS],x[SAMPS]; int i(0),j(0); struct timeval val1,val2; struct timespec a,b; double thetime1,thetime2; clock_gettime(CLOCK_REALTIME,&a); for (int k(0); k < 100; k++) for ( i = 0; i < TAPS+SAMPS; i++ ) { y[i].real = 0; // set to zero before sum y[i].imag = 0; // set to zero before sum for ( j = 0; j < TAPS; j++ ){ if ( i-j < 0 ) break; if ( i-j >= SAMPS ) continue; y[i].real += h[j].real * x[i - j].real; // convolve: multiply and accumulate y[i].imag += h[j].real * x[i - j].imag; // convolve: multiply and accumulate y[i].imag += h[j].imag * x[i - j].real; // convolve: multiply and accumulate y[i].real += -1.0*(h[j].imag * x[i - j].imag); // convolve: multiply and accumulate } } clock_gettime(CLOCK_REALTIME,&b); thetime1 = (double)((double)a.tv_sec+(double)(a.tv_nsec)/1.0e9); thetime2 = (double)((double)b.tv_sec+(double)(b.tv_nsec)/1.0e9); printf("Conv Time: %.9f\n",(thetime2-thetime1)); return 0; }
- 12-16-2011 #2
Even when it exits, that memory is still reserved in case it has to call that program again. Granted, if another program comes along and needs the memory it will be given up, but otherwise the system will hold it.
linux user # 503963
- 12-16-2011 #3Just Joined!
- Join Date
- Aug 2011
- Posts
- 51
But what is it caching? If the program starts again, it should (or not) be in a different piece of memory and then the cache would be dirty.


Reply With Quote
