Join With Me...

3:18 AM

Time program in C

#include
#include
int main()
{
clock_t st,end;
long i,j,t;
st=clock();
for(i=0;i<10000L;i++)
for (j=0;j<50000L;j++)
t=0;
end=clock();
printf("\nSTARTING CLOCK: %lf",(double)st);
printf("\nEnding Clock  : %lf",(double)end);
printf("\n%lf",(double)((end-st)/CLK_TCK));
return 0;
}

*/


#include
#include
main()

{
clock_t st,en;
 int arr[10000],*ptr=arr,n,t;
   float fir[5],sec[5],res;
   unsigned long i,j;
    for(t=0;t<5;t++)
      {
       st=clock();
for(j=0;j<10000L;j++)
 for(i=0;i<10000;i++)
  {
     arr[i]=1;
      }
en =clock();
printf("\nFIRST :  %lf\n",fir[t]=(en-st)/CLK_TCK);
st=clock();
 for(j=0;j<10000L;j++)
  for(i=0;i<10000;i++)
   {
     *(ptr+i)=1;
      }
 en =clock();
 printf("SECOND: %lf",sec[t]=(en-st)/CLK_TCK);

 printf("\nDIFFERENCE  :  %lf\n",*(fir+t)-*(sec+t));
      }
   
    for(t=0;t<5;t++)
     res=res+*(fir+t)+*(sec+t);
     printf("\nTOTAL TIME IS : %lf\n",res);
     res=0;
    for(t=0;t<5;t++)
             res=res+(*(fir+t)-*(sec+t));
     printf("\nTOTAL TIME SAVE IS :%lf\n",res);
     printf("\n\nEND");
     return 0;
      }

0 comments:

Post a Comment