AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"Benchmarking" scripting styles (sort of...)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Zippo



Joined: 21 Apr 2006
Posts: 56
Location: East Coast, USA

PostPosted: Sun Apr 22, 2007 7:30 am    Post subject: "Benchmarking" scripting styles (sort of...) Reply with quote

This is a little script that "benchmarks" different ways of writting the same bit of script. It is not meant to be scientific in the measurements, but it does give you an idea of how your scripting style effects script speeds.

I wrote this a while back for giggles and out of curiosity. Most of the old-timers probably already know all of this stuff, but it might help someone.

At any rate, I found some of the results interesting Smile

The hotkeys a, b, c and d run the various 'tests'. Escape exits the script.

Code:
;##########################################################################################
;##########################################################################################



a::
;==========================================================================================
ToolTip, Running test 1...
StartTime :=
a := 5000000

StartTime := A_TickCount
Loop, 50000000
{
  a :=
}
MsgBox % A_TickCount-StartTime



ToolTip, Running test 2...
StartTime :=
a := 50000000

StartTime := A_TickCount
Loop, 50000000
  a :=
MsgBox % A_TickCount-StartTime
ToolTip

Return
;==========================================================================================



;##########################################################################################
;##########################################################################################



b::
;==========================================================================================
ToolTip, Running test 1...
StartTime :=
a := 0

StartTime := A_TickCount
Loop, 5000000
  a := a+1
MsgBox % A_TickCount-StartTime



ToolTip, Running test 2...
StartTime :=
a := 0

StartTime := A_TickCount
Loop, 5000000
  a++
MsgBox % A_TickCount-StartTime
ToolTip

Return
;==========================================================================================



;##########################################################################################
;##########################################################################################



c::
;==========================================================================================
ToolTip, Running test 1...
Gosub LoopVsGotoTest1
ToolTip, Running test 2...
Gosub LoopVsGotoTest2Prt1
ToolTip
Return

LoopVsGotoTest1:
StartTime :=
a := 0

StartTime := A_TickCount
Loop
{
  a++
  If a = 5000000
    Break
}
MsgBox % A_TickCount-StartTime
Return



LoopVsGotoTest2Prt1:
StartTime :=
a := 0
StartTime := A_TickCount
Gosub, LoopVsGotoTest2Prt2
MsgBox % A_TickCount-StartTime
Return

LoopVsGotoTest2Prt2:
  a++
  If a = 5000000
   Return
Goto, LoopVsGotoTest2Prt2
;==========================================================================================



;##########################################################################################
;##########################################################################################



d::
;==========================================================================================
ToolTip, Running test 1...
StartTime :=
a := 0
b := 0
c := 0

StartTime := A_TickCount
Loop, 5000000
{
  If (a=0) && (b=0) && (c=0)
    c := 1
  Else
    c := 0
}
MsgBox % A_TickCount-StartTime



ToolTip, Running test 2...
StartTime :=
a := 0
b := 0
c := 0

StartTime := A_TickCount
Loop, 5000000
{
  If a=0
    If b=0
      If c=0
        c := 1
      Else
        c := 0
}
MsgBox % A_TickCount-StartTime
ToolTip

Return
;==========================================================================================



;##########################################################################################
;##########################################################################################
Esc::ExitApp

_________________
____________________
Back to top
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Wed Apr 25, 2007 9:30 pm    Post subject: Reply with quote

That

Code:

Loop
  ...


performs a lot better than

Code:

Loop  {
  ...
  }


was new to me. Surprised
Not that I ever use redundant braces, but it's still interesting. Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group