« Return to Thread: Measuring Execution Time

Re: Measuring Execution Time

by peteb :: Rate this Message:

Reply to Author | View in Thread

If you just want to measure the time your program was executing, just run it with the time command at the command prompt. That returns the clock time and CPU time used. Very handy. Won't work for measuring bits of the app, but otherwise might be  useful as it doesn't require you to add time code to your application.

# time app
#
# real Xm XXs
# user Xm XXs
# sys Xm XXs

Peter Vandrish wrote:
Thanks again Dave!

On Thu, May 22, 2008 at 2:00 PM, Dave Hylands <dhylands@...> wrote:
Hi Pete,

> I am trying to measure the execution time of my program using the following
> code:
> #include <ctime>
> clock_t start,finish;
> double time;
>
>
> start = clock();
> sort something
> finish = clock();
>
>
> time = (double(finish)-double(start))/CLOCKS_PER_SEC;
>
> It does not seem accurate at all. It reports that the Gumstix
> CLOCKS_PER_SECOND is 1000000.
>
> It also tells me the double(finish) is 30000 and the double(start) is 20000,
> it doesnt seem likely
>
>
>
> that my program executes in a nice round number of 10000 CLOCK TICKS.
>
> Does anyone know hoe I can do this well.

Try using the gettimeofday function.
<http://linux.die.net/man/2/gettimeofday>

On some version of linux (running on the PXA processors) this will
return sub-microsecond resolution, while on others it will return 10
millisecond resolution.

Note that gettimeofday will return wall time, as opposed to processor time.

You may also want to look at the times function:
<http://linux.die.net/man/2/times>

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gumstix-users mailing list
gumstix-users@...
https://lists.sourceforge.net/lists/listinfo/gumstix-users


------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________ gumstix-users mailing list gumstix-users@... https://lists.sourceforge.net/lists/listinfo/gumstix-users


-- 
Pete

Funny=Truth
Truth=Beauty
So take it as a complement when people say you look Funny.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gumstix-users mailing list
gumstix-users@...
https://lists.sourceforge.net/lists/listinfo/gumstix-users

 « Return to Thread: Measuring Execution Time