CPU Time

This is a discussion on CPU Time within the C Programming forums, part of the General Programming Boards category; Is there a C function that can calculate the CPU usage time for a process? or is there a way ...

  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,789

    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,796
    >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,789

    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, 12:45 PM
  2. Determine the closest departure time
    By Kyeong in forum C Programming
    Replies: 9
    Last Post: 10-07-2008, 09:06 PM
  3. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21