elapsed time testing

This is a discussion on elapsed time testing within the C Programming forums, part of the General Programming Boards category; 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); ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    20

    elapsed time testing

    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.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1)why the following test programs are not working?
    Probably because you didn't read the Announcements, you didn't use code tags, and you're using void main. Try reading and following my sig.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Aug 2004
    Posts
    128
    me thinks part of your problem is
    other then what he already said to you is
    Code:
    cprintf("%c",32);
    is used alot, and if you ment to use 32...
    why not just :

    Code:
    cprintf("32");
    im thinking, your not meaning to use 32,
    im thinking your meaning to use i :

    Code:
    cprintf("%c",i);

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    cprintf("%c", 32); and cprintf("32"); are not the same thing. One prints "32" and the other prints a space on systems using the ASCII character set...although putchar(' '); is certainly a lot more clear (and portable) about it.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Times I'm getting
    By afflictedd2 in forum Linux Programming
    Replies: 8
    Last Post: 07-23-2008, 07:18 AM
  2. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 06:17 AM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21