I want function to count the time

Discussion in 'C' started by fulla, Mar 20, 2011.

  1. fulla

    fulla New Member

    Joined:
    Mar 6, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    hi..

    i want help for function that can count the time from start function to eand it ..

    in c++ thr is function but i never use it i want help how can i use it..
    thanks
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main ( ) {
    time_t t;
    clock_t start, end;
    long i,count= 100000000;
    
    start = clock();
    
    time(&t);
    
    printf(ctime(&t));
    printf( "Counting to %ld\n", count );
    
    for (i=0; i < count; i ++);
    
    end = clock();
    
    printf( "That took %f seconds and I counted up to %ld", (((double)(end-start)/CLOCKS_PER_SEC)), count );
    getchar();
    return 0;
    } 
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice