|
本帖最后由 changlianxi 于 2012-7-18 16:30 编辑
我不是AAuto的枪手,再次更改帖子,只测试AutoIt3
AutoIt3循环测试结果
[0] 循环方法和累加方法 耗时(秒) 循环次数 耗时比例
[1] For.To.Next $a+=1 25.762 123456000 1.00
[2] For.To.Next $a=$a+1 54.133 123456000 2.10
[3] For.To.Step.Next $a+=1 25.818 123456000 1.00
[4] For.To.Step.Next $a=$a+1 54.450 123456000 2.11
[5] While.WEnd $a+=1 88.908 123456000 3.45
[6] While.WEnd $a=$a+1 122.898 123456000 4.77
[7] Do.Until $a+=1 91.669 123456000 3.56
[8] Do.Until $a=$a+1 122.881 123456000 4.77
[9] For.In.Next $a+=1 132.217 123456000 5.13
[10] For.In.Next $a=$a+1 159.829 123456000 6.20
循环123456000次
累加方法A+=1快于A=A+1,特别是For.To.Next循环,能快一倍多!
For用时(STEP声明与否差别不大)25秒
While Wend用时88秒
Do Until用时91秒
For In Next用时132秒
au3源代码
#include <Array.au3>
Dim $sArray[11][4]=[["循环方法和累加方法"],["For.To.Next $a+=1"],["For.To.Next $a=$a+1"],["For.To.Step.Next $a+=1"],["For.To.Step.Next $a=$a+1"],["While.WEnd $a+=1"],["While.WEnd $a=$a+1"],["Do.Until $a+=1"],["Do.Until $a=$a+1"],["For.In.Next $a+=1"],["For.In.Next $a=$a+1"]] ;数组初始化
$sArray[0][1]="耗时(秒)"
$sArray[0][2]="循环次数"
$sArray[0][3]="耗时比例"
Local $a = 0 ,$list =1 ,$i = 0, $j = 0
Local $begin = TimerInit()
For $i = 1 To 1000
For $j = 1 To 123456
$a+=1
Next
Next
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
For $i = 1 To 1000
For $j = 1 To 123456
$a=$a+1
Next
Next
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
For $i = 1 To 1000 Step 1
For $j = 1 To 123456 Step 1
$a+=1
Next
Next
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
For $i = 1 To 1000 Step 1
For $j = 1 To 123456 Step 1
$a=$a+1
Next
Next
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
Local $i = 0, $j = 0
While $i < 1000
While $j < 123456
$a+=1
$j += 1
WEnd
$i += 1
$j = 0
WEnd
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
Local $i = 0, $j = 0
While $i < 1000
While $j < 123456
$a=$a+1
$j += 1
WEnd
$i += 1
$j = 0
WEnd
_list()
;MsgBox(0,"a=",$a)
$a=0
Local $i = 0, $j = 0
$begin = TimerInit()
Do
Do
$a+=1
$j += 1
Until $j >= 123456
$i += 1
$j = 0
Until $i >= 1000
_list()
;MsgBox(0,"a=",$a)
$a=0
Local $i = 0, $j = 0
$begin = TimerInit()
Do
Do
$a=$a+1
$j += 1
Until $j >= 123456
$i += 1
$j = 0
Until $i >= 1000
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
Local $ii[1000], $jj[123456]
For $i In $ii
For $j In $jj
$a+=1
$j += 1
Next
$i += 1
$j = 0
Next
_list()
;MsgBox(0,"a=",$a)
$a=0
$begin = TimerInit()
Local $ii[1000], $jj[123456]
For $i In $ii
For $j In $jj
$a=$a+1
$j += 1
Next
$i += 1
$j = 0
Next
_list()
;MsgBox(0,"a=",$a)
Func _list()
$sArray[$list][1] = Round(TimerDiff($begin)/1000,3)
$sArray[$list][2] =$a
$sArray[$list][3] =Round($sArray[$list][1]/$sArray[1][1],2)
$list += 1
EndFunc
_ArrayDisplay($sArray)
|
|