February 2009 - Posts

Another Look at the Pixel-Plotting Tests

Thanks to codeimp's comment on my previous post, I went back to my pixel-plotting test app to add-in a LockBits method to see how it would stand up to the pure GDI+ methods.

As it turns out, I found that a poorly-placed "End If" was causing the code to not draw 100,000 pixels per test ... but only 10,000 per test.  Once I corrected that, I noticed that there was some time gaps starting to show between the methods.  So, I jacked up the test amount to 1 million pixels per test and I added-in the LockBits approach as an 8th way to go about things.

 On my ancient game dev laptop (1GHz P3), I got the following results (in seconds):

1 - DrawRectangle: 52.10
2 - FillRectangle: 42.90
3 - DrawEllipse: 59.34
4 - FillEllipse: 52.03
5 - DrawLine: 48.83
6 - DrawImage: 119.28
7 - DrawString: 79.32
8 - LockBits: 24.07

The relative speed of the LockBits is impressive.  However, I was surprised that the DrawImage approach was the slowest way to go.  And, FillRectangle looks to be the best of the standard GDI+ routines.

Now, keep in mind that these times are for 1 million plots, pausing every 1000 to invalidate the target PicBox and run a DoEvents to update the screen.  In a normal game situation, you're likely to only need to draw a few thousand specks (at most) and you won't be pausing in the middle of it to make sure the screen updates.

There were a couple other asthetic things that I noticed as well. The Rect methods are incapable of drawing a true single pixel ... their definition forces both methods to draw a 2x2 square instead.  Both Ellipse methods and the DrawLine method make 2-pixel long lines.  This leaves the last 3 methods for being the only ones to give you true single pixels per plot.

LockBits comes out looking pretty good.  The negative is that it takes a special bulk routine to make it efficient ... can't have each individual dot work as its own object that draws itself when requested.  The GDI+ routines do allow for individual drawing at the expense of speed (and some asthetics).

Posted by MattWorden | with no comments
Filed under: ,

Interesting Pixel-Plotting Efficiency Test Results

I recently ran a little experiment to see which would be the fastest way to plot a bunch of single pixels using the methods available in the System.Drawing namespace.  It turns out, for those who haven't looked, that there is no set-pixel type method because everything is built to work with various unit scales -- some of which have no use for single-pixel work.

I tested DrawRectangle, FillRectangle, DrawEllipse, FillEllipse, DrawLine, DrawImage (using a 1x1 rectangle from a memory bitmap that had been pre-built to have a bunch of randomly colored pixels), and even DrawString (at the right point size, the period is essentially a single pixel).  I ran each one through 100,000 pixels and stopwatch timed each one ... turns out that they were all within a couple tenths of a second of one another (less than 1% difference), except for DrawString -- that one was a couple seconds slower across 100,000 dots than the others.

So, I guess that means it really doesn't matter how you go about doing it ... just pick the method that fits the best into the code and gives the best on screen results.

(btw, I am still working on the "It's All About the Cameras" post that I promised last time ...)

Posted by MattWorden | 2 comment(s)
Filed under: ,