What is more faster ...

Blitz3D Forums/Blitz3D Programming/What is more faster ...

Eole(Posted 2004) [#1]
Hi all !

What is more faster betwwen a bank and an imagebuffer, I must do some zoom (not a scale), blend etc ...

thank


Rob Farley(Posted 2004) [#2]
Why not do some speed tests?


AntonyWells(Posted 2004) [#3]
bank is faster. in blitz+ you can use lockedpixels to get a bank of the imagebuffer directly, which is the fastest method I've heard. havn't used B+ since the demo, so don't know if it's true or not.


Eole(Posted 2004) [#4]
Yes it s really faster ... But is it possible to switch a bank memory into an imagebuffer

Graphics3D 800,600,32,2
SetBuffer BackBuffer()
Global nicolas

nicolas = CreateImage(512,512)

bk = CreateBank(512*512*4)

colorrgb = 210 Or (100 Shl 8) Or (10 Shl 16)

start = MilliSecs()
For x=1 To 512
For y=1 To 512
WritePixel x,y,colorrgb,ImageBuffer(nicolas)
Next
Next

Print MilliSecs()-start


start = MilliSecs()
For y=0 To 511
For x=0 To 511
PokeInt bk,(y*512+x )*4,colorrgb
Next
Next
Print MilliSecs()-start


WaitKey()


Eole(Posted 2004) [#5]
Little correction with lockbuffer and read/write operation

Graphics3D 800,600,32,2
SetBuffer BackBuffer()
Global nicolas

nicolas = CreateImage(512,512)

bk = CreateBank(512*512*4)

colorrgb = 210 Or (100 Shl 8) Or (10 Shl 16)

start = MilliSecs()
LockBuffer ImageBuffer(nicolas)
For x=1 To 512
For y=1 To 512
test=ReadPixelFast ( x,y,ImageBuffer(nicolas))
WritePixelFast x,y,colorrgb,ImageBuffer(nicolas)
Next
Next
UnlockBuffer ImageBuffer(nicolas)
Print MilliSecs()-start


start = MilliSecs()
For y=0 To 511
For x=0 To 511
test=PeekInt (bk,(y*512+x )*4)
PokeInt bk,(y*512+x )*4,colorrgb
Next
Next
Print MilliSecs()-start



WaitKey()


Eole(Posted 2004) [#6]
A very interresting thing look at this, It s more faster to compute operation in a bank an copy the bank in the imagebuffer than directle compute the operation in the imagebuffer



Graphics3D 800,600,32,2
SetBuffer BackBuffer()
Global nicolas

nicolas = CreateImage(512,512)

bk = CreateBank(512*512*4)

colorrgb = 210 Or (100 Shl 8) Or (10 Shl 16)

Print "Read / Write from an ImageBuffer"
start = MilliSecs()
LockBuffer ImageBuffer(nicolas)
For x=1 To 512
For y=1 To 512
test=ReadPixelFast ( x,y,ImageBuffer(nicolas))
WritePixelFast x,y,colorrgb,ImageBuffer(nicolas)
Next
Next
UnlockBuffer ImageBuffer(nicolas)
Print MilliSecs()-start

Print "Read / Write from a banck)
start = MilliSecs()
For y=0 To 511
For x=0 To 511
test=PeekInt (bk,(y*512+x )*4)
PokeInt bk,(y*512+x )*4,colorrgb
Next
Next
Print MilliSecs()-start

Print "Read/Write from a banck, an copy the result in ImageBuffer"
start = MilliSecs()
LockBuffer ImageBuffer(nicolas)
For y=0 To 511
For x=0 To 511
test=PeekInt (bk,(y*512+x )*4)
PokeInt bk,(y*512+x )*4,colorrgb
test=PeekInt (bk,(y*512+x )*4)
WritePixelFast x+1,y+1,colorrgb,ImageBuffer(nicolas)
Next
Next
UnlockBuffer ImageBuffer(nicolas)
Print MilliSecs()-start



WaitKey()


TartanTangerine (was Indiepath)(Posted 2004) [#7]
It's the ReadPixelFast which is not so fast.


TartanTangerine (was Indiepath)(Posted 2004) [#8]
I also found that storing the values in arrays are much faster than banks.. On My PC I get 20ms for the array and 112ms for banks.

width = 1024

Dim test(width ,width )
bank = CreateBank(width *width )

Print"Array"
start = MilliSecs()
For x = 0 To width -1
For y = 0 To width -1
test(x,y) = 1
a = test(x,y)
Next
Next
Print MilliSecs() - start

Print"Bank"
start = MilliSecs()
For x = 0 To width -1
For y = 0 To width -1

a=PeekInt (bank,((y*width )+x ))
PokeInt bank,((y*width )+x ),1

Next
Next
Print MilliSecs() - start

WaitKey()



Eole(Posted 2004) [#9]
It 's true, sometime I don't understand the blitz ...


mrtricks(Posted 2004) [#10]
Your grammar is incorrect. It's not "more faster". It's "more quicklier".


Eole(Posted 2004) [#11]
thank


Abomination(Posted 2004) [#12]
@ Flynn
Your Calculations are not very economical ;)
Try this:

width = 1024

Dim test(width ,width )
bank = CreateBank(width * width * 4 )

Print"Array"
start = MilliSecs()
For x = 0 To width -1
For y = 0 To width -1
test(x,y) = 1
a = test(x,y)
Next
Next
Print MilliSecs() - start

Print"Bank"
width4=width * 4
start = MilliSecs()
x1=0
For x = 0 To width -1
y1=0
For y = 0 To width -1

a=PeekInt (bank,(y1+x1 ))
PokeInt bank,(y1+x1 ),1
y1=y1+4
Next
x1=x1+width4
Next
Print MilliSecs() - start

WaitKey()


jhocking(Posted 2004) [#13]
"Your grammar is incorrect. It's not "more faster". It's "more quicklier"."

Um, he was joking. It's just "faster," not "more faster," and definitely NOT "more quicklier."


Ricky Smith(Posted 2004) [#14]
More quicklier is more better than more faster but more worse than more slowlily is more faster than more quicker !


WolRon(Posted 2004) [#15]
Reading from video RAM is much slower than reading from system RAM.

This is true.


mrtricks(Posted 2004) [#16]
@Joe: Did you think I was serious?


Pete Rigz(Posted 2004) [#17]
I think abomination had the quickest way, but this can also be handy if you multiply alot by powers of 2:

function GetShiftValue(p)
   repeat
      p=p shr 1
      c=c+1
   until p=1
   return c
end function


So now you can binary shift by c instead of multiply/divide by p.

so instead of

PeekInt (bk,(y*512+x )*4)


you have

texshift=getshiftvalue(width)
...
PeekInt (bk,((y shl texshift)+ x ) shl 2)


maybe it saves like 0.000001ms :P but maybe if you need to read the bank or multiply lots of times per loop its worth it.

*Edit: Weird, binary shifting on my work PC (crappy celeron 333) makes no difference at all! Strange, because on an old pc like that I'd have thought it would. oh well.