Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>clock() returns elapsed cpu time</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 clock()                 Returns elapsed CPU time

 #include   <time.h>

  clock_t clock(void);

    clock() tells how much processor time has been used by an operation.
    Intervals can be measured between an initial and an ending call to
    clock(). The time in seconds can be approximated by dividing the
    clock return value by the value of the CLK_TCK macro, defined in
    time.h.

    Returns:    clock() returns the time in seconds times the value of
                the CLK_TCK macro (1000). If clock() is unable to access
                the processor time it returns the value -1, cast as
                clock_t.

   Portability:     ANSI

 -------------------------------- Example ---------------------------------

 This program reports how many seconds a loop executes

           #include <time.h>

           main()
           {
              clock_t proc_time;
              int i;
              unsigned long j = 0;

              for (i=0; i < 500; i++)
                 {
                 j += (unsigned long) 2 * i;
                 printf("\tLoop %lu\n", j);
                 }

              if ((proc_time = clock()) != (clock_t) -1)
                 printf("Loop executed for %u seconds\n",
                 (unsigned) proc_time/CLK_TCK);
              else
                 printf("Processor time not available\n");
           }


See Also: difftime() time()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson