Raw pixel performance version 1.11 to 1.35 slowdown?
BlitzPlus Forums/BlitzPlus Programming/Raw pixel performance version 1.11 to 1.35 slowdown?
| ||
Below is a code sample that runs much slower on versions 1.35 and 1.34 compared to version 1.11. Basically it uses ReadPixelFast and WritePixelFast on an image bufer and the canvas. The numbers I get are version 1.11 - 1900 millisecs version 1.35 - 14500 millisecs That's about 7x slower. I thought perhaps it was the canvas operations, but commenting out the write to the canvas is still slower. version 1.11 - 600 millisecs version 1.35 - 900 millisecs I suspect I'm doing something wrong but I don't know what. ; Simple Speed test of read and write pixels Const EVENT_MOUSEDOWN = $201 Const EVENT_CLOSE = $803 Const IMAGE_WIDTH = 400 Const IMAGE_HEIGHT = 400 ; Create a main window window = CreateWindow ("Speed Test of raw pixel ops", 0, 0, ClientWidth(Desktop()), ClientHeight(Desktop())) If window ; Create panel panel = CreatePanel (0, 0, ClientWidth(window), ClientHeight(window), window, 1) SetPanelColor panel, 64, 64, 64 SetGadgetLayout panel, 1, 1, 1, 1 ; Create drawing canvas canvas = CreateCanvas (0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, panel) SetGadgetLayout canvas,1,1,1,1 ; Create image buffer ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT) SetBuffer ImageBuffer (ibuffer) ; Main event loop... Repeat ; Wait for a window event... e = WaitEvent () ; Process the event... If e = EVENT_MOUSEDOWN Then LockBuffer CanvasBuffer(canvas) LockBuffer ImageBuffer(ibuffer) startTime = MilliSecs() For count = 0 To 100 For y = 0 To IMAGE_HEIGHT For x = 0 To IMAGE_WIDTH rrgb = ReadPixelFast(x,y) WritePixelFast x,y,rrgb SetBuffer CanvasBuffer (canvas) WritePixelFast x,y,rrgb SetBuffer ImageBuffer (ibuffer) Next Next Next UnlockBuffer CanvasBuffer(canvas) UnlockBuffer ImageBuffer(ibuffer) endTime = MilliSecs() Print endTime - startTime FlipCanvas (canvas) EndIf If e = EVENT_CLOSE Then End Forever Else Notify ("Failed to create window!", True) End EndIf |
| ||
ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT) Change the above line to either of the ones below, and re-run the test. I'll say no more. Managed Style: ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT,1,2) SysRam Style: ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT,1,4) Enjoy! :) |
| ||
I've given these suggestions a try. This first one resulted if very little change Managed Style: ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT,1,2) around 14500 millisecs This second suggestion slowed things down even more. SysRam Style: ibuffer = CreateImage (IMAGE_WIDTH, IMAGE_HEIGHT,1,4) around 26000 millisecs Any other suggestions? Has the management of canvases changed since 1.11? Thanks Ken |
| ||
Personally I never use a canvas for reading/writing direct to. I only use SysRam images for that. It's far quicker. Try your example with the main write loop as this. (in both versions). I would be interested to know the results. ; Process the event... If e = EVENT_MOUSEDOWN Then SetBuffer ImageBuffer (ibuffer) LockBuffer ImageBuffer(ibuffer) startTime = MilliSecs() For count = 0 To 100 For y = 0 To IMAGE_HEIGHT For x = 0 To IMAGE_WIDTH rrgb = ReadPixelFast(x,y) WritePixelFast x,y,rrgb Next Next Next UnlockBuffer ImageBuffer(ibuffer) SetBuffer CanvasBuffer(canvas) DrawBlock iBuffer,0,0 endTime = MilliSecs() Print endTime - startTime FlipCanvas (canvas) EndIf If e = EVENT_CLOSE Then End |
| ||
Also, consider using LockedPixel()'s method. This again, is very fast. |
| ||
HI, The repeated use of SetBuffer inside the loop might be problem. Use the 'buffer' options of ReadPixel/WritePixel to control which buffers are read/written and remove the SetBuffers. |
| ||
Snarty, Thanks for your feedback. I've tried your version and the results are version 1.11 - 510 millisecs version 1.35 - 720 millisecs Of course this version changes the test so that the canvas is not updated along the way. The reason I was writting the pixels directly to the canvas was that the information I may normally have to display is not very dense, and in earlier tests on 1.11 it was quicker to just update the pixels rather than the full dirty rect. I also had previously tried the LockedPixel() method and I couldn't get this to perform as well as the readpixelfast(), of course my approach may not have been the best. Mark, Thanks for this suggestion, not doing the SetBuffer()'s in the loop shaved 4000 millisecs (or 25 percent). Are canvases created using video ram? Thanks Ken |