How can improve speed?

Just starting out? Need help? Post your questions and find answers here.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 685
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

How can improve speed?

Post by minimy »

Hello im trying to copy window (or canvas, image) content to another window,, how can improve speed?
Thanks for help!

Code: Select all

Procedure   copyThis(w1,w2)
  Protected   img
  StartDrawing(WindowOutput(w1))
    img= GrabDrawingImage(#PB_Any,0,0,OutputWidth(),OutputHeight())
  StopDrawing()
  StartDrawing(WindowOutput(w2))
    DrawImage(ImageID(img),0,0,OutputWidth(),OutputHeight())
  StopDrawing()
  FreeImage(img)
EndProcedure  

Procedure   draw(w1)
  Static x=-100
  StartDrawing(WindowOutput(c))
  For p= 0 To 100
    Box(0,0,OutputWidth(),OutputHeight(),$ffffff)
    Circle(x,150,100,$0000ff)
    x+1:If x>OutputWidth():x=-100:EndIf
    DrawText(10,10,Str(x),$0,$ffffff)
  Next p
  StopDrawing()
EndProcedure

OpenWindow(0,0,0,400,300,"W1",#PB_Window_SystemMenu)
OpenWindow(1,500,0,400,300,"W2",#PB_Window_SystemMenu)

t= ElapsedMilliseconds()
For p= 1 To 100
; Repeat
  event= WindowEvent()
  If event= #PB_Event_CloseWindow
    Break
  EndIf
  draw(0)
  copyThis(0,1)
;   Delay(1)
; ForEver
Next p
MessageRequester("Time", Str(ElapsedMilliseconds()-t) +" ms")
If translation=Error: reply="Sorry, Im Spanish": Endif
SMaag
Enthusiast
Enthusiast
Posts: 327
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How can improve speed?

Post by SMaag »

Why you want to speed up and what you want to speed up?

Your Code context look like you want to speed up the CopyThis()

I tested what is slow:
and it is not the CopyThis()

My timing:
With CopyThis 1130ms
without CopyThis 940ms

CopyThis needs 190ms only!

So the draw() Procedure is the bottleneck!

DrawText(10,10,Str(x),$0,$ffffff) ; 200ms
Circle(x,150,100,$0000ff) ; 650ms
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: How can improve speed?

Post by Psychophanta »

One of the fastests ways to manage bitmaps in windows is to treat it as "device independent bitmap (DIB)".
So please take a look at my source in:
viewtopic.php?p=200273#p200273
And take a look at the webpage I'm referring to there. :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
minimy
Enthusiast
Enthusiast
Posts: 685
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: How can improve speed?

Post by minimy »

Thanks to both for comments and help.
is true, the speed is not bad :lol:
If translation=Error: reply="Sorry, Im Spanish": Endif
Post Reply