find CPU Time for a function (subsecond precision)


 
Thread Tools Search this Thread
Top Forums Programming find CPU Time for a function (subsecond precision)
# 1  
Old 02-22-2005
find CPU Time for a function (subsecond precision)

Hi,

I need to time a certain function in my C/C++ code and I am experiencing some difficulties. I timed it using wallclock time so I know that it takes approximately 500-600 microseconds with

gettimeofday(&start, NULL);
// my function call
gettimeofday(&end, NULL);
answer = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec);

What I actually need is to get the CPU time used for this function. Unfortunately, the widely used clock() function does not give me a good precision because well... clock_t/CLOCKS_PER_SEC is in seconds.

Anyone had a similar problem? Thank you in advance.

Note: I couldn't find anything relevant on the Unix man pages or anywhere on this forum but it's always possible that I have overlooked...
# 2  
Old 02-22-2005
man getitimer
I think this will do what you want. But I've never used it except with ITIMER_REAL.
# 3  
Old 02-23-2005
Thanks for the quick pointer. I will look into it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Ps command on cpu usage and time

Hi All, Am very new to Linux and unix ...need below help . need to list of process consuming more than 40% cpu and which are older than 10 days of a particular user .... Thanks V (4 Replies)
Discussion started by: venky456
4 Replies

2. UNIX for Advanced & Expert Users

Cpu time

Hi Experts, If a thread running on CPU needs some data from RAM (from near or far RAM) it requests the data (this moment of time is t0) and gets it in moment of time in t1, and continues his work. Between t0 and t1, while data is transferring from RAM, the thread is goes out from CPU? Is the... (2 Replies)
Discussion started by: sant
2 Replies

3. Shell Programming and Scripting

what would a script include to find CPU's %system time high and user time high?

Hi , I am trying to :wall: my head while scripting ..I am really new to this stuff , never did it before :( . how to find cpu's system high time and user time high in a script?? thanks , help would be appreciated ! :) (9 Replies)
Discussion started by: sushwey
9 Replies

4. Solaris

process CPU time

We are using JAVA program and strange thing is it takes 100% CPU when not in use. The program function is to stream a file on output port (one direction). It checks one directory and when there is a file in it, starts. While it is streaming the CPU usage is normal, about 20%. But, if... (9 Replies)
Discussion started by: orange47
9 Replies

5. UNIX Desktop Questions & Answers

Killing a process if it is not using any cpu time

Hi i am a newbie thanks in advance i have a process which keeps on running but doesn't use any CPU time and doesn't do the functionality which it is suppose to do . If i kill the process and start the process again then the process kicks in and starts using CPU time and continues to do its... (3 Replies)
Discussion started by: nick1982
3 Replies

6. UNIX for Advanced & Expert Users

How to get access time of a file upto the precision of seconds?

Hi , How can I get the last access time of a file upto the precesion of seconds in Unix. I cannot use stat as this is not supported. (10 Replies)
Discussion started by: kanus
10 Replies

7. Shell Programming and Scripting

Why CPU time is longer than Elasped time?

I thought a program's elapsed time, some program language call it real time, should be the time of a program from start to finish. And it should be equal or longer than CPU time. This is true for the most of the cases. However, I do see some of my programs CPU time is longer than Elapsed time. ... (1 Reply)
Discussion started by: visio2000
1 Replies

8. UNIX for Advanced & Expert Users

how to know which process consume CPU time more

Hi, I have problem like everyday i have to check which process consuming more cpu time. I have done it manually using top command.. Is there any script which will tell the exact process name which will consuming more time. I am using hpux. (1 Reply)
Discussion started by: rajesh08
1 Replies

9. HP-UX

how to calculate CPU time under HP-UX

Hi, I am loking for a c++ function that calculate CPU time under HP-UX Thank you (1 Reply)
Discussion started by: limame
1 Replies

10. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies
Login or Register to Ask a Question