Performance comparisons for GDI on Windows mobile--managed code and local code

Source: Internet
Author: User

In forums or mail groups, there are often friends who say that to improve the performance of graphics applications, you must use local code (c + +) for development. We also often hear that local code is much faster than managed code in three-dimensional graphics. However, this is not exactly the case, and this article explores the performance issues of managed and local code on graphics operations through experimental data on multiple platforms. Keywordsgdi, C + +, C #, Windows Mobile,. NET Compact framwork, performance local code test let's take a look at the local Code test program first. The code is simple, just for testing. This program draws a rectangular bitmap field and creates the corresponding DC (device context), and then repeats the following two actions 10,000 times: one is to continuously fill the rectangular field with gray, and the second is to continuously draw the green ellipse in the middle of the rectangular field. The long axis short axis of the ellipse is constantly changing, which avoids the effect of the display driver cache on our test. The main code is as follows:

...
SCREENDC = GETWINDOWDC (NULL);
BUFFERDC = CreateCompatibleDC (SCREENDC);
Oldpen = (hpen) SelectObject (BUFFERDC, CreatePen (ps_null, 0, NULL));
Oldbrush = (hbrush) SelectObject (BUFFERDC, CreateSolidBrush (#00ff00));
Hbufferbmp = CreateCompatibleBitmap (SCREENDC, Box_width, box_height);
Oldobject = SelectObject (BUFFERDC, hbufferbmp);
rect.top = 0;
Rect.left = 0;
Rect.right = Box_width;
Rect.bottom = Box_height;
for (i = 0; i < Gdi_iterations_per_report; i++)
{
width + + xop;
height+= YOP;
if (width >= box_width) | | (width <= 0))
XOP *=-1;
if ((height >= box_height) | | (height <= 0))
YOP *=-1;
R + + ROP;
G + + GOP;
B + + bop;
if (R > 254) | | (r< 1))
ROP *=-1;
if ((g > 254) | | (g< 1))
GOP *=-1;
if ((b> 254) | | | (b< 1))
Bop *=-1;
Boxbrush = CreateSolidBrush (RGB (R, G, b));
FillRect (BUFFERDC, &rect, Boxbrush);
DeleteObject (Boxbrush);
Ellipse (BUFFERDC, width, height, box_width-width, box_height-height);
Ellipse (BUFFERDC, height, width, box_width-height, box_height-width);
BitBlt (SCREENDC, left, top, left + box_width, top + box_height,
BUFFERDC, 0, 0, srccopy);
}
...

Operation Effect as shown:

The test result is that on the Windows Mobile 5.0 emulator, the speed of the loop is 490 times per second (of course this is related to the performance of your PC). Each operation includes the process of populating the rectangle and drawing the two ellipses. On the actual device of a Windows Mobile 5.0 Dell Axim x51 (PXA270 processor), this program can be up to 250 cycles per second.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.