* difference w.r.t time
@ 2004-09-27 7:42 Ankit Jain
0 siblings, 0 replies; only message in thread
From: Ankit Jain @ 2004-09-27 7:42 UTC (permalink / raw)
To: linux prg; +Cc: gcc
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-09-27 7:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-27 7:42 difference w.r.t time Ankit Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).