Results 1 to 7 of 7

Thread: Which is faster?

  1. #1
    Guest

    Post

    This...
    Code:
    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...
    Code:
    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);

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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?
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Guest
    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.

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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,
    Harry.

    "From one thing, know ten thousand things."

  5. #5
    Guest
    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.

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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.
    Harry.

    "From one thing, know ten thousand things."

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Time to be controversial...

    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width