Re: 2D graphics & speed quest

Tech-Archive recommends: Fix windows errors by optimizing your registry



<snip>
Actually, PolyLine() _is_ faster. It's just that your test code causes
other things to happen that are not being taken into account. Remember,
I'm talking about the speed of PolyLine versus the equivalent bunch of
LineTo calls, and so I'm only interested in the time _those specific
routines_ take to draw their output, without anything else getting in the
way of the results. The problem with the code you posted is that a whole
bunch of display refreshes is going on at the same time, which tends to
swamp things.

The display is being invalidated and refreshed at just the same rate, if
anything PolyLine() should have the upper hand since it could wait until
it's finished drawing until it invalidates the display but it doesn't appear
to be the case.

If you use your exact same code but set the Form's Autoredraw property to
True you will see an entirely different result. Both of them (PolyLine and
the bunch of LineTo stuff) will of course be very much faster than they
were before (because we've got the display refreshes out of the way) and
in addition you'll see that PolyLine is actually very much faster than the
bunch of LineTo calls. Most people do most of their drawing to offscreen
buffers anyway, and only dump the result to the screen when it is done, so
drawing to an offscreen buffer is a perfectly valid way of testing the
speed of these things. At this end I'm getting a massive speed increase
all round (as you would of course expect) and I'm seeing PolyLine about _a
hundred times faster_ than the equivalent bunch of LineTo statements.
Here's your own code but using Autoredraw = True. Let me know what you get
at your end.

Oddly enough, enabling AutoRedraw only seems to slow down LineTo() here
while providing no performance increase to PolyLine():
PolyLine(): 3182.70
LineTo(): 2320.58

Without AutoRedraw (i.e. my original code, for comparison):
PolyLine(): 3055.79
LineTo(): 1665.58

If I create a new screen-compatible DDB and DC behind the scenes, and draw
to those rather than touching the form at all:
PolyLine(): 3198.33
LineTo(): 2085.72

Using a 24-bit DIBSection as the back buffer I get:
PolyLine(): 4962.22
LineTo(): 5104.24

16-bit DIBSection:
PolyLine(): 4349.79
LineTo(): 4115.74

And finally a 32-bit DIBSection:
PolyLine(): 5480.77
LineTo(): 5592.94

(All back-buffers were created at 1000*1000)

Why disabling back-buffering should increase the speed of LineTo() and not
PolyLine(), I have no idea but I've gone back and re-tested the results 3
times now and I'm getting consistent measurements.
I am at a loss to explain why on-screen drawing is actually faster than
drawing to a back-buffer though (the timing does _not_ take into account the
blit time to flip this buffer to the screen, this is only the drawing)
I'm running on a 1.9Ghz Dell Inspiron 8200 laptop with 1GB RAM and an nVidia
GeForce Go 440 graphics card, unfortunately I'm in the middle of moving so
it's the only machine accessible in at the moment for comparison testing.

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/


.



Relevant Pages

  • Re: 2D graphics & speed quest
    ... 3600 for both LineTo and Polyline. ... LineTo calls, and so I'm only interested in the time _those specific ... Private Declare Function MoveToEx Lib "GDI32.dll" (ByVal hDC As Long, ... Dim MyPts() As PointAPI ...
    (microsoft.public.vb.general.discussion)
  • Re: 2D graphics & speed quest
    ... And yes, I did test before posting, which incidentally appears to be more than you did or you would almost certainly have noticed the problem with the PolyLine declaration in the code you posted, right?.. ... Remember, I'm talking about the speed of PolyLine versus the equivalent bunch of LineTo calls, and so I'm only interested in the time _those specific routines_ take to draw their output, without anything else getting in the way of the results. ... Private Declare Function MoveToEx Lib "GDI32.dll" (ByVal hDC As Long, ... Dim MyPts() As PointAPI ...
    (microsoft.public.vb.general.discussion)
  • Re: 2D graphics & speed quest
    ... PolyLine(): 7.8 LineTo(): 986.2 ... the drawing is taking place). ... drawing to the displayed Form or Picture Box is the best option if you ...
    (microsoft.public.vb.general.discussion)
  • Re: 2D graphics & speed quest
    ... PolyLine(): 2.6 LineTo(): 1327.0 ... AutoDraw = False No Button ... However, for PolyLine to achieve such a fast speed and for it to be more or less guaranteed on most systems you need to be drawing to the displayed Form or Picture Box directly and there needs to be no "holes" in the clipping region. ...
    (microsoft.public.vb.general.discussion)