i want to know why these programs dont give the same output i am trying to do benchmarking. 1st program is using malloc and another array i am not taking the allocations into account. i am just looking for for loop i dont understand why they show diff. time thanks ankit ****************************************** PROGRAM 1 #include<stdlib.h> #include<stdio.h> #include<sys/time.h> #define NR 4096 #define NC 4096 #define N NR*NC int main() { unsigned long i,j,k,d=2; double cont2=0,cont1=0,mean=0; struct timeval start,end; double *a;//,*a1; a1=malloc(sizeof(double)*N); k=0; for (i = 0; i < NR; i++) { for (j = 0; j < NC; j++) { *(a+i+j) = k; mean = mean+*(a+i+j); } } mean = mean/( (float)NR*(float) NC); gettimeofday(&start,NULL); /* here is the 2d contrast module*/ for (i = 0; i<(NR-d); i++) { for (j = 0; j<(NC-d); j++) { cont2 = cont2 +(*(a+i+d+j)-*(a+i+j))*(*(a+i+d+j)-*(a+i+j))+ +(*(a+i+j+d)-*(a+i+j))*(*(a+i+j+d)-*(a+i+j)); } } cont2 = cont2/(mean*mean); printf("contrast :(2D) %f\n", cont2); gettimeofday(&end,NULL); printf("Time :%ld ",(-start.tv_sec + end.tv_sec)); return 0; } ********************************************* Program 2 #include<stdlib.h> #include<stdio.h> #define NR 4096 #define NC 4096 #define N (NR*NC) int main() { unsigned long i,j,k,d=2; double cont2=0,cont1=0,mean=0; double a[NR][NC]={},a1[N]={}; struct timeval start,end; k=0; for (i = 0; i < NR; i++) { for (j = 0; j < NC; j++) { a[i][j] = k; mean = mean+a[i][j]; } } mean = mean/( (float)NR*(float) NC); gettimeofday(&start,NULL); // here is the 2d contrast module for (i = 0; i<(NR-d); i++) { for (j = 0; j<(NC-d); j++) { cont2 = cont2 +(a[i+d][j]-a[i][j])*(a[i+d][j]-a[i][j])+ +(a[i][j+d]-a[i][j])*(a[i][j+d]-a[i][j]); } } cont2 = cont2/(mean*mean); printf("contrast :(2D) %f\n", cont2); gettimeofday(&end,NULL); printf("Time :%ld",end.tv_sec - start.tv_sec); return 0; } ________________________________________________________________________ Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html