Computing.Net > Forums > Programming > elapsed time test

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to get for your free account now!

elapsed time test

Reply to Message Icon

Name: deian1
Date: October 12, 2004 at 14:57:28 Pacific
OS: dos
CPU/Ram: ====
Comment:

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.


Report Offensive Message For Removal

Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: October 13, 2004 at 08:00:59 Pacific
Reply:

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

Response Number 2
Name: BlueRaja
Date: October 13, 2004 at 20:19:34 Pacific
Reply:

I can't read what you're asking, due to poor indentation.

AKhalifman@hotmail.com


Report Offensive Follow Up For Removal
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: elapsed time test

Bat Time kepper www.computing.net/answers/programming/bat-time-kepper-/17047.html

Qbasic Alarm www.computing.net/answers/programming/qbasic-alarm/6990.html

Delete Files Older Then x-Days www.computing.net/answers/programming/delete-files-older-then-xdays/15229.html