- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Measuring execution time of a C function, with...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2009 02:10 AM
тАО12-30-2009 02:10 AM
We have a function (let's call it func_to_be_tested()) in our codebase. A drastic change has gone to this function during a recent fix. As a comparison, I need to measure the execution time for this particular function with my change, and compare that to the execution time of old/stock source.
something like
void main() {
/* get start time */
func_to_be_tested();
/* get end time */
/* time = end - start , print it */
}
The simplest way seemed to be using gettimeofday() but AFAIK this does not take into account the fact that it is not just my process running on the machine but a whole lot of others too. So, am trying to see if I can use any other API or clock/timer mechanism to measure the time spent by CPU (both the user CPU time + system CPU time) just for this particular function over a run, (and which does not take into account the time when my process gets off CPU and other process are running on the CPU)
Will HP Caliper help in this regard? OR can we use getrusage() and such APIs and obtain the required data?
Please suggest.
Basically, am of the opinion that I should be rather getting to know the number of CPU cycles spent on the particular function, to arrive at the required data. Please let me know if my understanding is incorrect.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2009 02:31 AM
тАО12-30-2009 02:31 AM
Solutionhttp://docs.hp.com/en/B2355-60127/times.2.html
Run times() once before calling your function, and store the results.
Call your function.
Run times() again. Subtract to get the user & system times spent by your function.
For extra precision, replace "call your function" with "call your function 1000 times with a simple loop", if your function allows that. Then divide your time result with 1000.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-30-2009 07:49 AM
тАО12-30-2009 07:49 AM
Re: Measuring execution time of a C function, with high precision
(This is illegal, main must be int.)
>Will HP Caliper help in this regard?
Yes provided the function takes enough time.
>Or can we use getrusage()
This probably isn't granular enough, unless you call it many times as MK suggested.
>I should be rather getting to know the number of CPU cycles spent on the particular function,
Provided you aren't making any system calls, or making the exact same ones.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-31-2009 12:38 AM
тАО12-31-2009 12:38 AM
Re: Measuring execution time of a C function, with high precision
pstat_getptoc(buf,sizeof(struct pst_status),1,getpid());
and use pst_usercycles, pst_systemcycles counters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-04-2010 09:36 AM
тАО01-04-2010 09:36 AM
Re: Measuring execution time of a C function, with high precision
If you can ensure that your program runs on a CPU "by itself" such that it is unlikely to be interrupted by another program etc, then you could also take the gettimeofday() path - or for less timing overhead, use gethrtime(). If you really wanted to get bare-bones, you would read CR16 on PA-RISC (the interval counter - perhaps it is CR15, the memory fades...) or the ITC (name?) on Itanium.