Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with timing

Status
Not open for further replies.

Barok

MIS
Dec 13, 2002
134
CA
i was making a tutorial on poking to the screen, and i found that my timing device was unreliable, as it often the time the programs took to run as 0. Can you guys help me? all the code is commented on. i'll outline the timing devices. here's my timer outside of the program.

t! = timer

'code... code...
print timer - t!

you'll find two of these, as one program uses pset, one uses poke.

'**********************begin code**************************

DEFINT A-Z '-this command makes all unsigned variables integers. it
'greatly speeds up this program.

DEF SEG = &HA000 '-this points the default segment to the graphics buffer.
'it is absolutely necessary for using poke, as pointing
'to the graphics buffer will make poke poke to the screen.
SCREEN 13 '-the screen resolution: 360x200x256: 360 pixels across,
'200 pixels up and down, and 256 colours available.
'**********************************************************
t! = TIMER '-this starts up our timer which will tell us how long

'it takes for the program to finish, clocking it.
'*****************************************************************
FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
FOR x = 0 TO 319 'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.

PSET (x, y), x MOD 256 '-we all know pset i hope. this will plot the coordinates
'then show the colour of our pixel.
NEXT 'moves on to the next x.
NEXT 'moves on to the next y.

'************************************************************

PRINT TIMER - t! 'after the program is finished, this will print how long
'in milliseconds it takes.
'******************************************************************
DO: LOOP UNTIL INKEY$ <> &quot;&quot; 'irrelevent for now, but it waits for a keypress.

CLS 'clears the screen. i heard line(0,0)-(319, 199), 0, bf
'is alot faster though.

ti! = TIMER '-this starts up our timer which will tell us how long
'it takes for the program to finish, clocking it.


FOR y = 0 TO 199 '-these two loops will be the size of the pretty little
'we're going to make. notice it is 0 to 199 and 0 to 319
'this is because we start counting at 0 not 1.

FOR x = 0 TO 319

'offset& = y * 320& + x will plot the point.surprisingly,
offset& = y * 320& + x

'this is faster than pset even though this is a double integer. lets break it down. 'ignore the & in the 320&.

'you know that the screen is 320 pixels wide. is it ringing 'a bell yet? y * 320& will determine how high

'to plot the pixel. here's how it 'works. poke does not work with two dimensions: it works with one. you

'know how to 'plot a point on a grid? (x, y) y is up and down, x is sideways. however, poke is 'different.

'it is plotted with just (offset&). the offset& is the address... the 'coordinates for the screen. the actual

'offset& of the entire screen is 319 * 199 ('remember 0!). if the offset is 319, it will put a pixel at the

'top right hand corner
'of the screen. if it is 320, you would think it has gone off the screen, right? (the 'screen is 0-319), but

'no! you see, poke is sort of like microsoft word. if your 'typing and you reach the end of the page, the

'text moves to the next row and 'continues from the beginning column. so 320 will be 1 row down and at the

'first 'column. so if y = 0 and x = 100, then the forumla is 0 * 320& + 100. 0 * 320 is 0, and 0 + 100 is '

100. so therefore it moves over 100 columns and puts a pixel there. if y = 3 and x = 100, then the formula

'is 3 * 320 + 100. 3 * 320 is 960. 960 + 100 is 1060. want to find the x and y? for formula is offset& = y *

'360 + x. the offset is 1060, so therefore 1060 = y * 360 + x. 1060/360= y + x. Now, we're going to have

'remainders. 360 goes into 1060 three times with a remainder of 100... y = 1060/360, rounded down. x is the

'remainder. so y = 3, (1060/360 rounded down) and x = 100 (the remainder.) hope this helps. email me and

'tell me what you think!


POKE offset&, x MOD 256 'i explained this above. offset& is the address. x mod 256 is merely the color to

'make the pixel. you don't need to understand this.


NEXT 'next x coordinate.
NEXT 'next y coordinate.


PRINT TIMER - ti! 'prints out how long this program takes.

DO: LOOP UNTIL INKEY$ <> &quot;&quot; 'irrelevant. waits for a keypress.

 
YOU MIGHT TRY T# INSTEAD OF T! FOR HIGHER ACURACY...

When times are that low it is sometimes better to run a series of test then get an average...
T# = Timer
For I = 1 to 100
For x...
...
Next
Next
T# = Timer - T#
T = T# / 100


Also, See test 3 & 4 for faster routines...
DEFINT A-Z
DIM OFFY&(199)
'PRECALCULATE OFFSETS FOR TEST 4
FOR I = 0 TO 199
OFFY&(I) = I * 320&
NEXT

DEF SEG = &HA000
SCREEN 13
LOCATE 1: PRINT &quot;PRESS A KEY TO START...&quot;
DO: LOOP UNTIL INKEY$ <> &quot;&quot;
T1# = TIMER
FOR I = 1 TO 100
FOR Y = 0 TO 199
FOR X = 0 TO 319
PSET (X, Y), I
NEXT
NEXT
NEXT
T1# = TIMER - T1#
T1# = T1# / 100
LOCATE 1: PRINT T1#
DO: LOOP UNTIL INKEY$ <> &quot;&quot;

CLS
LOCATE 1: PRINT &quot;PRESS A KEY TO START...&quot;
DO: LOOP UNTIL INKEY$ <> &quot;&quot;
T2# = TIMER
FOR I = 1 TO 100
FOR Y = 0 TO 199
FOR X = 0 TO 319
offset& = Y * 320& + X
POKE offset&, I
NEXT
NEXT
NEXT
T2# = TIMER - T2#
T2# = T2# / 100
LOCATE 1: PRINT T2#
DO: LOOP UNTIL INKEY$ <> &quot;&quot;

CLS
LOCATE 1: PRINT &quot;PRESS A KEY TO START...&quot;
DO: LOOP UNTIL INKEY$ <> &quot;&quot;
T3# = TIMER
FOR I = 1 TO 100
FOR L& = 0 TO 63999
POKE L&, I
NEXT
NEXT
T3# = TIMER - T3#
T3# = T3# / 100
LOCATE 1: PRINT T3#
DO: LOOP UNTIL INKEY$ <> &quot;&quot;

CLS
LOCATE 1: PRINT &quot;PRESS A KEY TO START...&quot;
DO: LOOP UNTIL INKEY$ <> &quot;&quot;
T4# = TIMER
FOR I = 1 TO 100
FOR Y = 0 TO 199
FOR X = 0 TO 319
POKE OFFY&(Y) + X, I
NEXT
NEXT
NEXT
T4# = TIMER - T4#
T4# = T4# / 100
LOCATE 1: PRINT T4#
DO: LOOP UNTIL INKEY$ <> &quot;&quot;

CLS
PRINT &quot;TEST 1: &quot;; T1#
PRINT &quot;TEST 2: &quot;; T2#
PRINT &quot;TEST 3: &quot;; T3#
PRINT &quot;TEST 4: &quot;; T4#

[/b]
On A 2.0 GHz P4, my times are...
T1 : .0346
T2 : .0335
T3 : .0246
T4 : .0209

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
2 ghz? :bulging eyes:

(geez, hate not being able to use emoticons :p)

anyways, i did try #, and the same thing happened. don't have time yet for the others. try them later.
 
But you 'should' be able to get up to around 30 fps...
1 second / 30 frames = .03 seconds...

So those times should be more or less right...

As far as emotion icons...
Code:
[bugeyed]
= [bugeyed]
Code:
[shocked]
= [shocked]
Code:
[hammer]
= [hammer]
Code:
[bomb]
= [bomb]

for more... click on the hyperlink 'Emoticons/smileys' below...
(above preview post)

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Barok,
If I understand right, your program just work so fast that timer shows 0...
Then you can put your code in a loop of size 100 and then divide time you got by 100.
That is, &quot;series of test&quot;, second line of CubeE101's advice. And the first piece of code he offered.

 
Just curious? What does your system run, barok? I have a 490 ghz and they are considered fairly slow now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top