IonicWind Software

IWBasic => General Questions => Topic started by: Brian on October 18, 2011, 12:19:29 PM

Title: Timing
Post by: Brian on October 18, 2011, 12:19:29 PM
Hi,

I know I have seen this somewhere before, but how do you get the time in seconds
that it takes a process to run, eg:

SUB DoSomeStuff
start a timer
run some code
end the timer and get an answer in a variable
ENDSUB

I have done a search, but must be putting in the wrong search terms

Brian
Title: Re: Timing
Post by: LarryMc on October 18, 2011, 01:16:38 PM
this will do fast timing:

DECLARE IMPORT,GetTickCount(),int 
openconsole
int x
int tstart=GetTickCount()
for x=1 to 1000000000

next x

int tstop=GetTickCount()
double elapse=tstop-tstart
setprecision 5
?elapse/1000.0, " seconds"


if you are trying to time stuff that takes minutes then  divide by 60000

LarryMc
Title: Re: Timing
Post by: Andy on October 18, 2011, 10:36:41 PM
Hi Brian,

Larry has a good answer, if you want a very simple way you can always do this:

declare three variable at the top of you program and use the built in command 'TIMER'

DEF starttime,endtime,elapsed:int

Then in your sub routine (or and part of your program you want to time), do this:

SUB mybitofcode
starttime = 0
endtime   = 0
elapsed   = 0

starttime = TIMER

'the code you want goes here

endtime = TIMER
elapsed = endtime - starttime

RETURN
ENDSUB

The variable 'elapsed' will have the number of seconds stored in it.

Hope this helps,
Andy.

Title: Re: Timing
Post by: Brian on October 19, 2011, 02:18:30 AM
Andy,

Larry's code worked, but I like your code - simple is good for me!

Brian