Jump to content

Can't Use a function with variables for AdlibRegister?? Maybe You can...


Bilgus
 Share

Recommended Posts

Apparently you can't use a function with variables for AdlibRegister

Like you declare it with a variable even an optional one and it throws an error if you try and call it

Thats ok though I figured out a hack using eval to get a better result

Registered_Funct(250);Register
Sleep(10000)
Registered_Funct(-1);UnRegister

Func Registered_Funct($iTime = -1)
    Local $i_Time = Eval("iTime")
    If $i_Time > 0 Then
        AdlibRegister("Registered_Funct", $i_Time)
    ElseIf $i_Time < 0 Then
        AdlibUnRegister("Registered_Funct")
    Else
        ConsoleWrite("Do Stuff")
    EndIf            
EndFunc


Surely it has an impact on efficiency though...

Edited by Bilgus
Link to comment
Share on other sites

Looks like it roughly doubles the amount of time to call the function

Local $iRep = 1000000
$t1 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct()
Next
$t1 = TimerDiff($t1)
$t2 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct2()
Next
$t2 = TimerDiff($t2)
$t3 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct3(0)
Next
$t3 = TimerDiff($t3)
ConsoleWrite($t1 & " MS " & $t2 & " MS " & $t3 & " MS" &@crlf)
;------------------------------------------------------------
$t1 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct(0)
Next
$t1 = TimerDiff($t1)
$t2 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct2(0)
Next
$t2 = TimerDiff($t2)
$t3 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct3(0)
Next
$t3 = TimerDiff($t3)
ConsoleWrite($t1 & " MS " & $t2 & " MS" & $t3 & " MS" &@crlf)
;------------------------------------------------------------
$t1 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct(0)
Next
$t1 = TimerDiff($t1)
$t2 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct2(0)
Next
$t2 = TimerDiff($t2)
$t3 = TimerInit()
For $i = 0 To $iRep
    Registered_Funct3(0)
Next
$t3 = TimerDiff($t3)
ConsoleWrite($t1 & " MS " & $t2 & " MS " & $t3 & " MS" &@crlf)
;------------------------------------------------------------
Func Registered_Funct($iTime = -1)
    Local $i_Time = Eval("iTime")
    If $i_Time > 0 Then
        ;AdlibRegister("Registered_Funct", $i_Time)
    ElseIf $i_Time < 0 Then
        ;AdlibUnRegister("Registered_Funct")
    Else
        ;ConsoleWrite("Do Stuff")
    EndIf
EndFunc   ;==>Registered_Funct

Func Registered_Funct2($i_Time = -1)
    ;Local $i_Time = Eval("iTime")
    If $i_Time > 0 Then
        ;AdlibRegister("Registered_Funct", $i_Time)
    ElseIf $i_Time < 0 Then
        ;AdlibUnRegister("Registered_Funct")
    Else
        ;ConsoleWrite("Do Stuff")
    EndIf
EndFunc   ;==>Registered_Funct2

Func Registered_Funct3($iTime = -1)
    Local Static $i_Time = Eval("iTime")
    If $i_Time > 0 Then
        ;AdlibRegister("Registered_Funct", $i_Time)
    ElseIf $i_Time < 0 Then
        ;AdlibUnRegister("Registered_Funct")
    Else
        ;ConsoleWrite("Do Stuff")
    EndIf
EndFunc   ;==>Registered_Funct3
12233.3068867691 MS 7294.26714847837 MS 14831.9736167586 MS

21526.1075779184 MS 12244.615865983 MS 14880.1448228755 MS

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...