Zippo
Joined: 21 Apr 2006 Posts: 56 Location: East Coast, USA
|
Posted: Sun Apr 22, 2007 7:30 am Post subject: "Benchmarking" scripting styles (sort of...) |
|
|
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
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 |
_________________ ____________________ |
|