AutoHotkey Community

It is currently May 26th, 2012, 2:42 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 93 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7  Next
Author Message
 Post subject:
PostPosted: November 21st, 2008, 9:12 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Pil wrote:
Reading HelpFile further it says "It also improves DllCall's performance when unquoted parameter types are used (e.g. int vs. "int")"
Unquoted parameter types are variable references, so the above is merely a result of the preceding point,
Quote:
Source: AutoHotkey Documentation: #NoEnv
It significantly improves performance whenever empty variables are used in an expression or command.

Pil wrote:
Further HelpFile is confusing about explaining use of quotes in DllCall, I can´t find something written like -using quotes gives better performance-
My own benchmarks indicated that using variables containing parameter types marginally outperforms quoted strings or empty variables (with #NoEnv). There are at least two reasons for this:
  • Variable and function references are resolved at load-time, whereas literal strings are parsed each time the expression is evaluated. In other words, literal strings require more processing.
  • If a variable reference is used, DllCall checks the value contained by the variable first, then if that is not a valid type, the name of the variable.
The difference between quoted and unquoted is small enough that I would not base my choice on performance. I use quoted to avoid creating unnecessary variables (int, uint, str, etc.), or unquoted when I feel it would improve readability.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2008, 3:12 pm 
Offline

Joined: February 26th, 2006, 9:45 am
Posts: 55
Location: Recife Brazil
I am really happy with the new beta version.
With the use of GetProcAddress the DllCall is four times faster now.
The only script I have that doesn´t work anymore is the colorpicker written by SKAN that you (Lexikos) modified with machinecode.
Laszlo's machinecode examples still work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 10:14 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I get a 10% speed increase for the SetPixel example with GetProcAddress running on the new beta.

Could you link to the color picker? I can't seem to find it. I presumably used my __mcode function, which by design relies on the low-level format of certain structures. Chris has made "many low-level changes," most likely including changes to these structures.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 11:06 pm 
Offline

Joined: February 26th, 2006, 9:45 am
Posts: 55
Location: Recife Brazil
Indeed strange. Seems it also depends on the computer you use
I write my mails at a cyber cafe, and at the moment I use a Celeron 2.13 GHz 120 MB Ram
The average of 20 runs of SetPixel example with GetProcAddress = 953ms for AHK version 1.0.47.06 and 382ms for the beta version.
Still 2,5 times faster.
Stange you get only 10 %
I´ll put the Bitmap with __mcode on the LowLevel & dynamic code topic


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2009, 8:31 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
A wrapper for GetProcAddress:

Code:
MsgBox, % GetProcAddress( "winmm.dll", "mciSendStringA" )

GetProcAddress( DLL="",F="" ) {                                     
 Static I, D="Kernel32.dll",LL="LoadLibraryA",GMH="GetModuleHandleA",GPA="GetProcAddress"
 If !I
  I:=1, LL := _GPA(D,LL), GMH := _GPA(D,GMH), GPA := _GPA(D,GPA)
 Return DllCall( GPA,UInt,(H:=DllCall(GMH,Str,DLL)) ? H : DllCall(LL,Str,Dll), Str,F )
}

_GPA( DLL="",F="" ) {                                               
 Return DllCall( "GetProcAddress", UInt,(H:=DllCall( "GetModuleHandleA",Str,DLL) ) ? H
      : DllCall( "LoadLibraryA",Str,DLL), Str,F )
}


Edit: Rectified Code


Last edited by SKAN on January 18th, 2009, 3:58 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 8:29 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
SKAN wrote:
A wrapper for GetProcAddress:

Code:
MsgBox, % GetProcAddress( "Kernel32.dll","WideCharToMultiByte" )

GetProcAddress(DLL="",F="") {
 Static I, D="Kernel32.dll",LL="LoadLibraryA",GMH="GetModuleHandleA",GPA="GetProcAddress"
 If !I
  I:=1, LL := GPA(D,LL), GMH := GPA(D,GMH), GPA := GPA(D,GPA)
 Return DllCall( GPA,UInt,(H:=DllCall(GMH,Str,D)) ? H : DllCall(LL,Str,DllFile), Str,F ) 
}

GPA(D="",F="") {
 Return DllCall( "GetProcAddress", UInt,(H:=DllCall( "GetModuleHandleA",Str,D) ) ? H
      : DllCall( "LoadLibraryA",Str,DllFile), Str,F )
}


sorry for the stupid question: do shorter var names execute faster than longer names ???


because short names just makes code not readable or understandable...

sure, some guys/gals can understand it, but others just get confused by the shorts...


eg,

you meant something like:

Code:
; DLLAdd( "Kernel32.dll","WideCharToMultiByte" )
DLLAdd(DLL="",F="") {
   ;Global DLLAdd_Lib
   ;ebug(DLL " dll in " f)
   
    Static I, LL="LoadLibraryA",GMH="GetModuleHandleA",GPA="GetProcAddress"
   
    If !I      
      I:=1, LL := GetProcAddress("Kernel32.dll",LL), GMH := GetProcAddress("Kernel32.dll",GMH), GPA := GetProcAddress("Kernel32.dll",GPA)
   

   Return (result := DllCall(GPA
            , UInt
            , (H:=DllCall(GMH,Str,DLL) ) ? H
               : DllCall( LL,Str,DLL)
            , ( F + 0) ? "UInt" : "Str",F ))
         ? result : DLL "" F

}

GetProcAddress(D="",F="") {
 Return DllCall( "GetProcAddress"
            , UInt
            , (H:=DllCall( "GetModuleHandleA",Str,D) ) ? H
               : DllCall( "LoadLibraryA",Str,D)
            , ( F + 0) ? "UInt" : "Str",F )
}


(which while complaining, add that I don't like the "," approach to code... unless it saves speed, it just makes code not readable....

but what to I know...)

_________________
Joyce Jamce


Last edited by Joy2DWorld on January 14th, 2009, 11:10 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 8:42 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Joy2DWorld wrote:
sorry for the stupid question: do shorter var names execute faster than longer names ???
Not in this case. If you were using dynamic variable references, shorter might be faster, but not by enough.
Quote:
I don't like the "," approach to code... unless it saves speed, it just makes code not readable....
Executing one expression with multiple comma-delimited substatements is faster than executing the equivalent as multiple expressions. If used correctly, continuation lines can improve readability of long lines.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 11:19 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Joy2DWorld wrote:
sorry for the stupid question: do shorter var names execute faster than longer names ???

Why would you ever want to ruin the code like that. If your optimisation comes to the point where you think about length of variable names you should stop ASAP IMO. The similar thing I noticed recently where some guys did find important to optimise dotNet applications by using StringBuilder instead string. If I have to think how I use something so basic as string, then I don't want that language.

About "," lines, I use them to group related calculations. If it troubles you, you can use code like this:

Quote:
c = a+ b, d = x+y ;instead this use the thing bellow

c = a+b
,d = x+y


However, the same thing I said above applies here for me. I don't care if its faster, if single line is not readable I am going to use multiple lines.

It also comes to be a personal thing. Your version is far less readable to me then original due to the line splitted DllCalls that I don't like at all except for functions with very larg number of arguments, like CreateWindow. IMO, with small function (small = small number of lines) readability is improved with shorted variable names and shorter expressions.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 6:17 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
Lexikos wrote:
Executing one expression with multiple comma-delimited substatements is faster than executing the equivalent as multiple expressions. If used correctly, continuation lines can improve readability of long lines.


that is worth knowing. thanks.


@majkinetor,

not normally do that (dll split) but wanted to spread out so could see why that version works, and 'original' shorthanded version, not.)

point is (without saying it) shortanded vars confuse those who write the code sometimes... let alone the rest of us.... (or some of us anyhow).

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2009, 4:02 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Joy2DWorld wrote:
could see why that version works, and 'original' shorthanded version, not.)


Thanks for noticing.. I have rectified it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 10:37 pm 
Offline

Joined: February 26th, 2006, 9:45 am
Posts: 55
Location: Recife Brazil
I must say that since I started this topic i am happy with AHK´s progress.
But still come back to this topic because I noticed that not only the dllCall but also the NumPut is very slow. I remembered SKAN´s code in the beginning using just one dllCcall and creating the bitmap array with NumPut. Using this code as test, I included a common slider, but soon I saw that this is a slow control. I asume it`s a API control, so nothing to do with AHK. So I created a custom control as in following code.
Only try this on a relative fast computer. On mine it takes 20 seconds to load 256 bitmaps (on my old mmx 233, 5 minutes).After loaded the colorpicker works smoothly.

Code:
#NoEnv
ATC:=A_TickCount
SetBatchLines -1
DetectHiddenWindows, On
Gui, +ToolWindow +LastFound
Gui = WinExist()
hDC:=DllCall("GetDC",UInt,Gui)
Gui, Font, s12 w200, Arial
Gui, Add, Text, x290 y261 w10 h20 gMoveIt, >
Gui, Add, Text, x320 y261 w10 h20 gMoveIt, < 
Gui, Add, Text, x300 y15 w20 h256  0x120E hWndhPic
Gui, Add, Text, x20 y15 w256 h256 0x120E hWndhPic2 gSelColor


;Draw blue slider picture.
VarSetCapacity(bi,40,0),VarSetCapacity(spa,20480,0)
NumPut(40,bi,0),NumPut(20,bi,4),NumPut(256,bi,8)
NumPut(1,bi,12,"UShort"),NumPut(24,bi,14,"UShort"),NumPut(20480,bi,20)
blue := 0,offset := &spa
Loop, 256 {
   blue++
   Loop, 20 {
      Offset := NumPut(blue , Offset +0 ) -1
   }
}
hBMP2 := DllCall( "CreateDIBitmap", UInt,hDC, UInt,&bi, Int,4,UInt,&spa, UInt,&bi,UInt,0 )       
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP2,, ahk_id %hPic%


;Prepare structure
W:=256
H:=256
Bit:=24
Byt:=W*H*4 ;(Bit/8)
VarSetCapacity(bmInfo,40,0)
VarSetCapacity(colorarray,Byt,0)
NumPut( 40,bmInfo,0 ) ; Size in bytes of bmInfo structure (40 bytes).
NumPut( W,bmInfo,4 )
NumPut( H,bmInfo,8 )
NumPut( 1,bmInfo,12,"UShort" ) ; The number of color planes. Always 1 in current bitmaps
NumPut( Bit,bmInfo,14,"UShort" ) ; The number of data bits of a single pixel.
NumPut( Byt,bmInfo,20 ) ; Size of bitmap

SplashTextOn , 400, 60,ColorPicker ,Please wait a few seconds...minutes??

;Creating 256 bitmaps increasing blue value
blue := 0,
Loop 256
   {
   red:=0,OffSet := &colorarray
         Loop 256
      {               
         red++, green:=0
         Loop 256
            Offset := NumPut(((red<<16)|(green++<<8)|blue) , Offset +0 ) -1
      }
         hBMP%blue% := DllCall( "CreateDIBitmap", UInt,hDC, UInt,&bmInfo, Int,4,UInt,&colorArray, UInt,&bmInfo,UInt,0 )
         blue++
   }
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP0,, ahk_id %hPic2%
SplashTextOff
Gui, Show, w340  h288, % "ColorPicker [ " (A_TickCount-ATC) "ms ]"
return

MoveIt:
xpos := 290
xpos2 := 320
loop {
   GetKeyState, OutputVar, LButton
   If OutPutVar = U
   break
   MouseGetPos, xps, ypos, id, control
   ypos -= 29
   If ypos > 261
   ypos := 261
   If ypos < 7
   ypos := 7
   GuiControl, Move,>,x%xpos% y%ypos%
   GuiControl, Move,<,x%xpos2% y%ypos%
   blue := 256 - (ypos - 6)
   If blue <> %oldBlue%
   SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP%blue%,, ahk_id %hPic2%
   oldBlue := blue
   }
return

SelColor:
 MouseGetPos, X, Y
 PixelGetColor,Color, X, Y, RGB
 Tooltip % SubStr(Color,-5)
 SetTimer, TooltipOff, -2000
Return

ToolTipOff:
ToolTip
Return

GuiClose:
ExitApp


Lexicos wrote low level code creating array, but unfortunatly it doesn´t work anymore with the newest fast beta version. Anyway you could not change the blue value with it. So I made a dll to do this.
If you want to try it, you can download it at http://www.autohotkey.net/~pil/MakeColorArray.dll
and use it with slightly modified code

Code:
NoEnv
ATC:=A_TickCount
SetBatchLines -1
DetectHiddenWindows, On
Gui, +ToolWindow +LastFound
Gui = WinExist()
hDC:=DllCall("GetDC",UInt,Gui)
Gui, Font, s12 w200, Arial
Gui, Add, Text, x290 y261 w10 h20 gMoveIt, >
Gui, Add, Text, x320 y261 w10 h20 gMoveIt, < 
Gui, Add, Text, x300 y15 w20 h256  0x120E hWndhPic
Gui, Add, Text, x20 y15 w256 h256 0x120E hWndhPic2 gSelColor


;Draw blue slider picture.
VarSetCapacity(bi,40,0),VarSetCapacity(spa,20480,0)
NumPut(40,bi,0),NumPut(20,bi,4),NumPut(256,bi,8)
NumPut(1,bi,12,"UShort"),NumPut(24,bi,14,"UShort"),NumPut(20480,bi,20)
blue := 0,offset := &spa
Loop, 256 {
   blue++
   Loop, 20 {
      Offset := NumPut(blue , Offset +0 ) -1
   }
}
hBMP2 := DllCall( "CreateDIBitmap", UInt,hDC, UInt,&bi, Int,4,UInt,&spa, UInt,&bi,UInt,0 )       
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP2,, ahk_id %hPic%


;Prepare structure
W:=256
H:=256
Bit:=24
Byt:=W*H*4 ;(Bit/8)
VarSetCapacity(bmInfo,40,0)
VarSetCapacity(colorarray,Byt,0)
NumPut( 40,bmInfo,0 ) ; Size in bytes of bmInfo structure (40 bytes).
NumPut( W,bmInfo,4 )
NumPut( H,bmInfo,8 )
NumPut( 1,bmInfo,12,"UShort" ) ; The number of color planes. Always 1 in current bitmaps
NumPut( Bit,bmInfo,14,"UShort" ) ; The number of data bits of a single pixel.
NumPut( Byt,bmInfo,20 ) ; Size of bitmap

SplashTextOn , 400, 60,ColorPicker ,Please wait a few seconds...minutes??

;Creating 256 bitmaps increasing blue value
hModule := DllCall("LoadLibrary", "str", "MakeColorArray.dll")
blue := 0,
Loop 256
   {
   addressColorArray := DllCall("MakeColorArray.dll\MakeArray" ,"char", blue)
   ;red:=0,OffSet := &colorarray
   hBMP%blue% := DllCall( "CreateDIBitmap", UInt,hDC, UInt,&bmInfo, Int,4,UInt,addressColorArray, UInt,&bmInfo,UInt,0 )
   blue++
   }
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP0,, ahk_id %hPic2%
SplashTextOff
Gui, Show, w340  h288, % "ColorPicker [ " (A_TickCount-ATC) "ms ]"
return

MoveIt:
xpos := 290
xpos2 := 320
loop {
   GetKeyState, OutputVar, LButton
   If OutPutVar = U
   break
   MouseGetPos, xps, ypos, id, control
   ypos -= 29
   If ypos > 261
   ypos := 261
   If ypos < 7
   ypos := 7
   GuiControl, Move,>,x%xpos% y%ypos%
   GuiControl, Move,<,x%xpos2% y%ypos%
   blue := 256 - (ypos - 6)
   If blue <> %oldBlue%
   SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP%blue%,, ahk_id %hPic2%
   oldBlue := blue
   }
return

SelColor:
 MouseGetPos, X, Y
 PixelGetColor,Color, X, Y, RGB
 Tooltip % SubStr(Color,-5)
 SetTimer, TooltipOff, -2000
Return

ToolTipOff:
ToolTip
Return

GuiClose:
ExitApp


As you can see in a few seconds the bitmaps are loaded.
It is not faster because slider picture is included in total time.
PS any one an idea about how to get rid of flickering?
Noel


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 11:20 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
SKAN wrote:
Joy2DWorld wrote:
could see why that version works, and 'original' shorthanded version, not.)


Thanks for noticing.. I have rectified it.


ouch. I hope you were gentle with it, at least....


just my point is that using super short vars is confusing...

and longer descriptive to all vars is.. well... avoids all that rectification stuff and what not....

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2009, 5:01 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Pil wrote:
But still come back to this topic because I noticed that not only the dllCall but also the NumPut is very slow.
It is not so much NumPut that is slow, but the script itself. AutoHotkey is not suited for this sort of intensive processing, even with the speed improvements of the beta.

Note that in this case you could gain a massive speed boost by using OpenGL or DirectX. It would require only four vertices to form two polygons, with each vertex a different colour. Bilinear filtering would take care of the gradient effect. Now that I think about it, you could probably even do it with GDI or GDI+, without 3D hardware.
Quote:
Lexicos wrote low level code creating array, but unfortunatly it doesn´t work anymore with the newest fast beta version.
Since the beta adds a field to the beginning of the Var structure, any code compiled to access the Var structure directly would need to be recompiled. In this case the function is not called frequently, so it is better to avoid the compatibility issues and use Laszlo's MCode. The function would be designed to accept a pointer to the data rather than a variable reference.

Edit: btw, Gui = WinExist() probably doesn't do what you intended. ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 12:04 am 
Offline

Joined: February 26th, 2006, 9:45 am
Posts: 55
Location: Recife Brazil
Quote:
It is not so much NumPut that is slow, but the script itself

Don´t get it.
I have replaced only the loop using Numput with ddl in second code, which reduced needed time from 20 seconds to 2,5.
Do you want better proof?

Quote:
Edit: btw, Gui = WinExist() probably doesn't do what you intended.
hehe, you are right. I was taken out all unnecessary stuff from SKAN´s code like BitmapInfoHeader and multiple window prefix. When removing all :99 I forgot to remove this command entirely.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2009, 7:27 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Pil wrote:
Don´t get it.
I have replaced only the loop using Numput with ddl in second code, which reduced needed time from 20 seconds to 2,5.
Do you want better proof?
Yes. The code you posted clearly consists of more than NumPut. By "the script itself", I refer to the loop, braces, expression evaluations and assignments. Everything takes time in semi-interpreted languages such as AutoHotkey, moreso than compiled languages.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 93 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group