Page 1 of 1

timing

Posted: Sun Feb 01, 2004 6:38 am
by yacinator
ok i made a sorting program and it works great. i got this idea that maybe i could display how long the sort took. at the beggining of the sort sub i put

let t1=timer

and at the end i put

let t2=timer

in the display sub i put print t2-t1 and it sais 0 so i put
print using #.##########; t2-t1 and it sais 0.00000
i'm wonderign if it sais 0 becouse it just doesn't work or becouse i didn't put enough #'s 'couse my pc is too fast and the list is too short. can somebody please try this and answer my question please ???

:)Re: timing

Posted: Sun Feb 01, 2004 8:25 am
by Dr_Davenstein
Try this...

SortTime&=Timer

' Do you sort routine....

Print Ltrim$(Str$(Timer-SortTime&))+" seconds for sort."

:)

Re: timing

Posted: Sun Feb 01, 2004 10:23 am
by yacinator
ok doc now it showed something, but what it showed was : %80335.6719 but i don't think that's how much time it took to do the calculations. oh by the way i changed the string sorttime to a number and used print using #.####. Can you please tell me why i get that number? ???

Re: timing

Posted: Mon Feb 02, 2004 3:03 pm
by frankiebaby
Where that percent sign came from, I dont kno, but that was not a string type, it was a  long integer. Try using a double precision number, an exclamation point. TIMER is capable of returning i think up to .01 of a second. Try this:


ST! = Timer  'start
'...LOOP CODE HERE....
ET! = Timer   'end

PRINT "Took "; ET!-ST!; "Seconds To Complete."

Re: timing

Posted: Wed Feb 04, 2004 5:30 am
by yacinator
frankie i got the same thing after adding ! to the end of the varible but i think i know why i get % before the number. this is probably wrong but maybe the number is so long that qb is trying to write it in scientific notation maybe. and i tried the timer with a program like this and i got an answer without a %.

Code: Select all

cls
for i=1 to 10000
print timer
select case i
case is= 1
let one= timer
case is= 10000
let two= timer
end select
next i
print one
print two
print two-one
end


and got something like  one= 62883.15, two=62883.37 and the diffrence was .2226563 without any % or other nuts.
thanks for your help