Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
1)why the following test programs are not working?
#include "stdio.h"
#include "time.h"int i,x,step;
time_t s1,s2;void main(void){
step=20;s1=time(NULL);
for(i=0;i<32;i++){
cprintf("%c",32);
}
cprintf("\n\r");
for(i=32;i<64;i++){
cprintf("%c",32);
}
s2=time(NULL);
cprintf("%f",difftime(s2,s1));
getch();s1=time(NULL);
for(i=0;i<64;i++){
if(i==32) cprintf("\n\r");
cprintf("%c",32);
}
s2=time(NULL);
cprintf("%f",difftime(s2,s1));
getch();
exit(0);
}
----------
#include "stdio.h"
#include "time.h"int i,x,step;
clock_t s1,s2;void main(void){
step=20;s1=clock();
for(i=0;i<32;i++){
cprintf("%c",32);
}
cprintf("\n\r");
for(i=32;i<64;i++){
cprintf("%c",32);
}
s2=clock();
cprintf("%ld",s2-s1);
getch();s1=clock();
for(i=0;i<64;i++){
if(i==32) cprintf("\n\r");
cprintf("%c",32);
}
s2=clock();
cprintf("%ld",s2-s1);
getch();
exit(0);
}
they show zeros and 1s.as i know, one of them should show time in seconds
elapsed at cicle execution and the other time in clock impulses.by the way,
what kind of impulses, from the external clock, or the clock speed of
instructions execution(at microcontrolers or other simple programmable
hardware,the external clock rate is divided at a integer which is a power of
2 resulting internal clock rate)?when we say that a PC runs at 100mhz which
clock rate is this?
2)it is a difference between tiny or other model generated by the compiler?
i've compiled the source file in tiny and medium model and except the size of
exe file and a "no stack" warning at tiny model i didn't noticed any
change in runing the programme.
I looked only at the first program. It appears that you get the current time, print a couple of lines of spaces, then get the current time again, then print the difference in the two times. Then you do roughly the same thing again and print the time difference.
You are doing so little between the two time statements (two 32 iteration for loops) that the time difference is easily under one second. I'd expect that it would even be under 1/100th of a second, which is the smallest time resolution that I've seen from C/C++ time routines.
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |