problem with clock()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prassaad
    New Member
    • Aug 2007
    • 16

    problem with clock()

    Hello Friends,
    I would like to calcute time required by any function
    e.g.
    start=clock();
    scanf("%d",&no) ;//i enter number & stop for 2 seconds
    end=clock()
    then i printed 'end -start'
    but it gives me answer=0
    Guide me for why clock() is not working
    I hv FEDORA 6.
    Tell me other way to solve my TIME PROBLEM.......
  • arne
    Recognized Expert Contributor
    • Oct 2006
    • 315

    #2
    Originally posted by prassaad
    Hello Friends,
    I would like to calcute time required by any function
    e.g.
    start=clock();
    scanf("%d",&no) ;//i enter number & stop for 2 seconds
    end=clock()
    then i printed 'end -start'
    but it gives me answer=0
    Guide me for why clock() is not working
    I hv FEDORA 6.
    Tell me other way to solve my TIME PROBLEM.......
    I usually use gettimeofday() for timing measurements in C:

    [CODE=c]
    #include <sys/time.h>
    ...
    struct timeval s, e;
    unsigned long tdiff;
    gettimeofday( &s, NULL );

    /* do your stuff here */

    gettimeofday( &e, NULL );
    tdiff = (e.tv_sec-s.tv_sec) * 1000000+(e.tv_u sec-s.tv_usec);
    [/CODE]

    HTH,
    Arne

    Comment

    Working...