Measuring Execution Time

View: New views
5 Messages — Rating Filter:   Alert me  

Measuring Execution Time

by Peter Vandrish :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
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.

Thanks,

Pete



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

Re: Measuring Execution Time

by Dave Hylands :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Measuring Execution Time

by Peter Vandrish :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Measuring Execution Time

by adrian cockcroft :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This data does make sense.

CPU time is charged by the clock interrupt at 100Hz in 10ms increments.

Your program had used 2 ticks at start and 3 ticks at finish. The time
is being scaled to microseconds. So your sort took between 1 and 19ms
of CPU time. If you run the code lots of times or loop the test and
average the result you can get a more accurate measure.

Adrian



On Thu, May 22, 2008 at 8:15 AM, Peter Vandrish
<peter.vandrish@...> wrote:

> Hi,
> 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.
>
> Thanks,
>
> Pete
>
>
> -------------------------------------------------------------------------
> 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

Re: Measuring Execution Time

by peteb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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