October 30, 2025, 05:21:29 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Timing

Started by Brian, October 18, 2011, 12:19:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

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.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

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

Brian