TestLimit = 100
Radius = 350
'Cls , &HFF000000 + Int(Rnd * &HFFFFFF)
k&
= &HFF000000 + Int(Rnd * &HFFFFFF)
Fill 512, 360, k&, 0
'Cls , &HFF000000 + Int(Rnd * &HFFFFFF)
k&
= &HFF000000 + Int(Rnd * &HFFFFFF)
Fill 512, 360, k&, -1
Print Using "###.#### seconds for Fill."; t1#
- t#
Print Using "###.#### seconds for Fill Method -1."; t2#
- t1#
Sub Fill
(Passx
, Passy
, kolor
As Long, METHOD
)
o = 0
'Else
'_MemPut m, m.OFFSET + o, 0 As LONG
o = o + 4
TempGrid(Passx, Passy) = 1
startx = Passx: finishx = Passx
starty = Passy: finishy = Passy
pass = pass + 1
finished = -1
For x
= startx
To finishx
For y
= starty
To finishy
'If TempGrid(x, y) <> 0 Then Print x, y, TempGrid(x, y): Sleep
tempx = x
If TempGrid
(tempx
- 1, y
) = 0 Then TempGrid(tempx - 1, y) = pass + 1
tempx = tempx - 1
If tempx
< startx
Then startx
= tempx
finished = 0
tempx = 0
tempx = x
If TempGrid
(tempx
+ 1, y
) = 0 Then TempGrid(tempx + 1, y) = pass + 1
tempx = tempx + 1
If tempx
> finishx
Then finishx
= tempx
finished = 0
tempy = y
If TempGrid
(x
, tempy
- 1) = 0 Then TempGrid(x, tempy - 1) = pass + 1
tempy = tempy - 1
If tempy
< starty
Then startx
= tempy
finished = 0
tempy = 0
tempy = y
If TempGrid
(x
, tempy
+ 1) = 0 Then TempGrid(x, tempy + 1) = pass + 1
tempy = tempy + 1
If tempy
> finishy
Then finishy
= tempy
finished = 0
o = 0
o = o + 4
[ You are not allowed to view this attachment ]
Now, if you guys look, there's only one difference in the code:
If METHOD Then
_MemCopy m1, m1.OFFSET, m1.SIZE To m, m.OFFSET
End If
The main process here works like this:
First, we make an array the size of the screen.
Then where the color exists that we want to use as a paint boundary, we assign a value of -1 to the grid in that position.
Then we do a little pathfinding style routine counting passes to fill in from the point we choose to the end of those boundaries...
Both routines work flawlessly. Neither has any issues doing what they're supposed to do.
In one (where we pass a method value of 0), the array has starts out empty with values of in it, and we assign a value of -1 to any point where the chosen color is...
In the other (where we pass a method value of anything but 0), we copy the whole array of screen colors over, and assign a value of -1 to any point where the chosen color is.. (Note, this can only work as long as our screen doesn't have any bright white characters printed on it, as it doesn't have in these instances here.)
Now, logically speaking, it would seem that one method would, indeed, be faster than the other. Wouldn't it be faster to go with a blank array, rather than first having to copy and alter every pixel from the screen onto the array? You'd think so...
...and, as the screenshot above illustrates, YOU'D BE WRONG!!
It's faster to copy the whole screen into our array -- a LOT faster -- than it is to NOT copy the screen. WTH?!! WHY??
Why is it faster to do MORE work than it is to SKIP that work???
I find the differences in the speed runs here to be mind boggling, and I can't sort out why the heck it's faster to do more work than it is to NOT do it.
Anyone want to take a shot at explaining why this has such different speed results with it? I'm completely baffled here.