Thread: Clock()

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Clock()

    The value the clock() function returns is a clock_t type, fine, BUT that value is in Hertzios or in what??

    Clock returns the number of system clock signals that occured since the start of the program, but I dont know if that means MHerzs or miliseconds used by the processor or what.
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    [email protected]

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    clock returns the number of clock ticks since the beginning of your program, to work out how long this was you need to use the CLOCKS_PER_SEC macro.
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main( void )
    {
    	clock_t start, stop;
    	long int x;
    	double duration;
    
    	start = clock();  // get number of ticks before loop
    
    	for( x = 0; x < 1000000; x++ );
    
    	stop = clock();  // get number of ticks after loop
    
    	// calculate time taken for loop
    	duration = ( double ) ( stop - start ) / CLOCKS_PER_SEC;
    
    	printf( "\nThe number of seconds for loop to run was %.2lf\n", duration );
    
    	return 0;
    }
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Not ansered

    And what is a clock tick?? Because in my program i use that function and it returns 3450 in 3 seconds and i really dont think that 3450 are seconds, so what unit is that?? a megahertz??

    That was my question in the first place.
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    [email protected]

  4. #4
    Registered User TravisS's Avatar
    Join Date
    Jun 2002
    Posts
    536
    Look closely at it, what does it look like? How could 3450 and 3 be related?

    3450/1000=3.45

    Get it? It is in 1/1000 seconds

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    It means, there were 3450 ticks in the clock to process what ever was in between the calls to the two clock()'s of your program.

    See the definition of CLOCKS_PER_SEC in the header file time.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 06:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. System clock
    By bazzano in forum C Programming
    Replies: 10
    Last Post: 03-27-2007, 10:37 AM