Thread: CPU Time

  1. #1
    Unregistered
    Guest

    CPU Time

    Is there a C function that can calculate the CPU usage time for a process? or is there a way to calculate the same?

    Thanks,
    Anoop.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: CPU Time

    Originally posted by Unregistered
    Is there a C function that can calculate the CPU usage time for a process? or is there a way to calculate the same?

    Thanks,
    Anoop.
    There are various profilers available......some compilers come with them

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is there a C function that can calculate the CPU usage time for a process?
    Code:
    clock_t time_function ( void (*func_to_time)(void) )
    {
      clock_t start, end;
    
      start = clock();
      /*
      ** Do some process.
      */
      func_to_time();
      end = clock();
    
      return end - start;
    }
    But keep in mind that a profiler is far more accurate. If your functions are quick then you will time them as 0 with this method.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Unregistered
    Guest

    what is...

    Hey Prelude!: )...where can one find the definition of the clock() func and the data type clock_t?

    cheers!

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: what is...

    Originally posted by Unregistered
    Hey Prelude!: )...where can one find the definition of the clock() func and the data type clock_t?

    cheers!
    <time.h> or <ctime> if you are c++ inclined!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. clock()
    By C_ntua in forum C Programming
    Replies: 19
    Last Post: 10-08-2008, 11:45 AM
  2. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 08:06 PM
  3. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  4. Upgrading my old CPU (for another old one!)
    By foxman in forum Tech Board
    Replies: 16
    Last Post: 01-11-2008, 05:41 PM
  5. CPU time / thread tool
    By Carlos in forum Windows Programming
    Replies: 2
    Last Post: 01-31-2003, 09:11 AM