954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

to find the execution time of a code

i have to find two time stamps one at the begining of main and at the end of main and take the difference to find the time elapsed to execute the code in between.Can anybody suggest the programs or proper API s in Linux.

shanthu123
Newbie Poster
1 post since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

>Can anybody suggest the programs or proper API s in Linux.
A profiler would be best. Check your system for the existence of gprof. You can also use a number of methods inside of your code to get execution time and timestamps, something like gettimeofday or rdtsc.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

man time
time does what u want.

youngstorm
Light Poster
25 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

that thread had a post that the execution time varies with compiler.... is it true...... what exactly does change from compiler to compiler........

aasi007onfire
Newbie Poster
23 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

There shouldn't be a "major" difference due to compilers, it's more to do with the platform (OS+H/W) then compiler.
Using same compiler you can use different optimization levels, this should make a visible difference in performance.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You