Jump to content
  • Advertisement
Sign in to follow this  
Marusu

Slow release debbuging

This topic is 3216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I use debug option to compile, I get normal performance and everything works fine, but when I switch to release, program executes 10 times longer. Here's the code:
#include <windows.h>
#include <windowsx.h>
#include <ctime>
#include <sstream>
#include <string>

LRESULT CALLBACK WindowProc (HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
double diffclock (clock_t clock1,clock_t clock2)
{
	double diffticks=clock1-clock2;
	double diffms=(diffticks*10)/CLOCKS_PER_SEC;
	return diffms;
}


int WINAPI WinMain (HINSTANCE instance, HINSTANCE noMoreUsedInstance, char * cmd, int windowType)
{
	UNREFERENCED_PARAMETER(noMoreUsedInstance);
	UNREFERENCED_PARAMETER(cmd);

	//Class name
	LPTSTR lpszClassName = L"Main class";

	WNDCLASSEX w;

	w.cbClsExtra = NULL;
	w.cbSize = sizeof(WNDCLASSEX);
	w.cbWndExtra = NULL;
	w.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
	w.hCursor = LoadCursor(NULL, IDC_ARROW);
	w.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	w.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
	w.lpfnWndProc = WindowProc;
	w.lpszClassName = lpszClassName;
	w.lpszMenuName = NULL;

	RegisterClassEx(&w);

	HWND handle = CreateWindowEx(NULL, lpszClassName, L"Main window", WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 800, 480, NULL, NULL, instance, NULL);

	ShowWindow(handle, windowType);
	UpdateWindow(handle);

	MSG m;

	while (GetMessage(&m, NULL, 0, 0) > 0)
	{
		TranslateMessage(&m);
		DispatchMessage(&m);
	}

	return m.wParam;
}

LRESULT CALLBACK WindowProc (HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;

	switch (message)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
			break;
		case WM_PAINT:
		{
			hdc = BeginPaint(handle, &ps);

			clock_t begin = clock();

			int x, y;
			for (int i = 0; i < 1000000; i++)
			{
				x = rand() % 800;
				y = rand() % 480;

				SetPixel(hdc, x, y, RGB(rand() % 255, rand() % 255, rand() % 255));
			}

			for (int i = 0; i < 100000; i++)
			{
				HPEN hPen = CreatePen(PS_SOLID, rand() % 5, RGB(rand() % 255, rand() % 255, rand() % 255));
				HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);

				LineTo(hdc, rand() % 800, rand() % 480);

				SelectObject(hdc, hOldPen);
				DeleteObject(hPen);
			}

			clock_t end = clock();

			
			double time = diffclock(end, begin);
			std :: wstringstream wss;
			wss << time;

			TextOut(hdc, 10, 10, wss.str().c_str(), wss.str().size());

			EndPaint(handle, &ps);
			break;
			return 0;
		}
	}

	return DefWindowProc(handle, message, wParam, lParam);
}

The size of release version is ~10KB and ~35KB of debug. What am I doing wrong? And what is the difference between release and debug options?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Marusu
When I use debug option to compile, I get normal performance and everything works fine, but when I switch to release, program executes 10 times longer.
Here's the code:
*** Source Snippet Removed ***
The size of release version is ~10KB and ~35KB of debug.
What am I doing wrong?

You don't ZeroMemory your WNDCLASSEX (and don't set all its fields), so the values of some of the fields (namely hInstance (!) and style) are left undefined. Switching between Debug and Release builds is causing these values to be initialized to different things in memory.

For your release build, what is probably happening (I can replicate it on my own machine if I try) is that the CS_DROPSHADOW style is being set for the class, which adds a drop shadow effect to the window. This slows down drawing operations, and hence the slowdown you are noticing.

The solution is to correctly zero out the WNDCLASSEX structure before using it, and to set the hInstance field as required:


WNDCLASSEX w;
ZeroMemory(&w, sizeof(w));

w.hInstance = instance;
// rest of class setup here


Quote:
And what is the difference between release and debug options?


Among other things, Debug mode includes debugging information with your binary (symbols, etc), while Release mode does not, and turns on optimizations (resulting in a smaller and (usually!) faster binary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!