PDA

Click to See Complete Forum and Search --> : Which is faster?


Oct 31st, 2000, 06:29 PM
This...

GetCursorPos(&Mouse);
Colors = GetPixel(GetWindowDC(ChildWindowFromPoint(WindowFromPoint(Mouse), Mouse)), Mouse.x, Mouse.y);

Red = GetRValue(Colors);
Green = GetGValue(Colors);
Blue = GetBValue(Colors);

SetDlgItemInt(hMainDialog, ID_EDIT_RED, Red, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_GREEN, Green, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_BLUE, Blue, FALSE);


Or
This...

GetCursorPos(&Mouse);
Window = WindowFromPoint(Mouse);
Window = ChildWindowFromPoint(Window, Mouse);
Hdc = GetWindowDC(Window);

Colors = GetPixel(Hdc, Mouse.x, Mouse.y);

//Extract RGB values
Red = GetRValue(Colors);
Green = GetGValue(Colors);
Blue = GetBValue(Colors);

//Set the edit boxes
SetDlgItemInt(hMainDialog, ID_EDIT_RED, Red, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_GREEN, Green, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_BLUE, Blue, FALSE);

HarryW
Oct 31st, 2000, 08:06 PM
I'd guess the first one, because it doesn't involve the three assignments for the second, third and fourth function calls. Why do you ask?

Oct 31st, 2000, 09:40 PM
Thats what i was thinking to0, but does anyone know for sure? I want to know cuz if it is, ill start coding that way.

HarryW
Oct 31st, 2000, 09:44 PM
We're talking about a difference of a few microseconds; those three assignments will boil down to maybe 10 or 20 CPU cycles. Compared to the function calls it makes a miniscule difference. I'd say stick to whatever makes your code clearer.

Besides, with compilers optimising code like they do, they might be identical once compiled anyway,

Oct 31st, 2000, 10:53 PM
Well that code goes into the msg loop, so its called like every time. So even a few microseconds every time it loops will speed it up alot.

HarryW
Oct 31st, 2000, 11:28 PM
I'm quite sure it won't. A microsecond is a millionth of a second. It depends on your CPU anyway. It's maybe 20 CPU cycles. 3 ASM instructions. How many cycles do you think a function like ChildWindowFromPoint() takes? A lot compared to an assignment.

I doubt if it makes a difference of 1% quite frankly.

parksie
Nov 1st, 2000, 12:51 PM
They'll take exactly the same time, because the compiler will create temporary variables, since from an ASM point of view, you can only do it the second way.