I created a shared library where I declare and share the data structure of a static 4K array (initialized). Then I access the static 4K array from Program1 several times and each time measure the access time to access the entire 4K static array. I got almost the same access time (about 17,000 ticks).
Now, if I access the same shared static array from another program2, I get almost 1/2 access time than program1. Again, after program2 accesses the shared static array, if I access the same static array in Program1 as before, I got almost 1/2 access time as the original OR almost the same access time as Program2.
Can someone explain to me why this is happening?
In case 1, before accessing the general data structure Program2, program1 will access the same general data structure several times. Therefore * why not reduce the access time for the second access * ?
In case 2, why does the access time in program2 get lower? after accessing the general data structure of access to program 2 , why does the access time in program1 get lower?
Here is my shared library :
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
static int DATA[1024]={1,2,3,4,.....1024};
inline void foo(void)
{
int j;
int k=0;
for(j=0;j<1024;j++)
{
k=DATA[j];
}
k+=0;
}
Program 1:
foo(); // do not measure time this time to avoid page fault
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program1, Before IPC, Time taken 1 = %llu\n",total_time);
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program1, Before IPC, Time taken 2 = %llu\n",total_time);
// USE IPC here , to receive signal
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program1, after IPC, Time taken 1 = %llu\n",total_time);
// USE IPC here , to send signal
// USE IPC here , to receive signal
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program1, after IPC, Time taken 2 = %llu\n",total_time);
Program2:
foo(); // do not measure time this time to avoid page fault
// USE IPC here , to send signal
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program2, after IPC, Time taken 1 = %llu\n",total_time);
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program2, after IPC, Time taken 2 = %llu\n",total_time);
// USE IPC here , to receive signal
start=rdtsc();
foo();
end=rdtsc();
temp=end-start;
total_time=temp;
printf("Inside Program2, after IPC, Time taken 3 = %llu\n",total_time);
Output Program1
Inside Program1, Before IPC, Time taken 1 =17200
Inside Program2, Before IPC, Time taken 2 =17200
**Inside Program1, after IPC, Time taken 1 = 8504**
**Inside Program1, after IPC, Time taken 2 = 7489**
Output Program2
Inside Program2, after IPC, Time taken 1 = 7500
Inside Program2, after IPC, Time taken 2 = 7600
**Inside Program2, after IPC, Time taken 3 = 8500** // Here access time increased as compared to previous