What is more faster ...
Blitz3D Forums/Blitz3D Programming/What is more faster ...
Hi all !
What is more faster betwwen a bank and an imagebuffer, I must do some zoom (not a scale), blend etc ...
thank
Why not do some speed tests?
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.
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()
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()
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()
It's the ReadPixelFast which is not so fast.
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()
It 's true, sometime I don't understand the blitz ...
Your grammar is incorrect. It's not "more faster". It's "more quicklier".
thank
@ 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()
"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."
More quicklier is more better than more faster but more worse than more slowlily is more faster than more quicker !
Reading from video RAM is much slower than reading from system RAM.
This is true.
@Joe: Did you think I was serious?
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.