脚本语言的执行速度
本帖最后由 magusneo 于 2012-5-16 12:49 编辑vbs,ahk_l,au3简单对比下,发现vbs很快而且是快得多,看起来专门处理运算不错
ahk时快时慢波动很大和是否开了其他空程序有关,au3速度较稳定有时比ahk_l快
在我机器上 vbs 59ms,ahk_l从180~360ms,au3 240~280ms
vbsFunction fibonacci(nn)
If nn = 0 Then
fibonacci = 0
Exit Function
End If
If nn <= 2 Then
fibonacci = 1
Exit Function
End If
fibonacci = fibonacci(nn-1) + fibonacci(nn-2)
End Function
testTimes = 20
nn = 23
totalTime = 0
minTime = -1
maxTime = -1
For ii = 0 To testTimes-1
begin = Timer
result = fibonacci(nn)
elapsed = Timer - begin
totalTime = totalTime + elapsed
If elapsed < minTime Or minTime = -1 Then minTime = elapsed
If elapsed > maxTime Then maxTime = elapsed
Next
averageTime = totalTime / testTimes *1000
MsgBox(_
"fibonacci(" & nn & ") ="& vbTab & result & vbCrLf & _
"testTimes:" & vbTab & testTimes & vbCrLf & _
"Average time:" & vbTab & averageTime & vbCrLf & _
"minTime:" & vbTab & minTime*1000 & vbCrLf & _
"maxTime:" & vbTab & maxTime*1000)ahk_l#NoEnv; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn; Recommended for catching common errors.
SendMode Input; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%; Ensures a consistent starting directory.
fibonacci(nn)
{
if ( 0 = nn )
return 0
if ( nn <= 2 )
return 1
return fibonacci(nn-1) + fibonacci(nn-2)
}
nn = 23
testTimes = 20
totalTime = 0
minTime = -1
maxTime = -1
Loop, % testTimes
{
StartTime := A_TickCount
result := fibonacci(nn)
elapsed := A_TickCount - StartTime
totalTime += elapsed
If (elapsed < minTime Or minTime = -1)
minTime := elapsed
If (elapsed > maxTime)
maxTime := elapsed
}
averageTime := totalTime / testTimes
MsgBox, 0, fibonacci, fibonacci(%nn%) = %result%`ntestTimes = %testTimes%`nAverage:%averageTime%`nminTime:%minTime%`nmaxTime:%maxTime%
au3Func fibonacci($nn)
If $nn = 0 Then Return 0
If $nn <= 2 Then Return 1
return fibonacci($nn-1) + fibonacci($nn-2)
EndFunc
$testTimes = 20
$nn = 23
$totalTime = 0
$minTime = -1
$maxTime = -1
For $ii = 0 To $testTimes-1
$begin = TimerInit()
$result = fibonacci($nn)
$elapsed = TimerDiff($begin)
$totalTime += $elapsed
If $elapsed < $minTime Or $minTime = -1 Then $minTime = $elapsed
If $elapsed > $maxTime Then $maxTime = $elapsed
Next
$averageTime = $totalTime / $testTimes
MsgBox(0, "fibonacci", _
"fibonacci(" & $nn & ") ="& @TAB & $result & @CRLF & _
"testTimes:" & @TAB & $testTimes & @CRLF & _
"Average time:" & @TAB & $averageTime & @CRLF & _
"minTime:" & @TAB & $minTime & @CRLF & _
"maxTime:" & @TAB & $maxTime)
小弟只有AU3 - -!
有图有真相 return fibonacci($nn-1) + fibonacci($nn-2)
这个递归是啥意思?求解释 回复 3# 3mile
斐波那契数列 这个什么书来着 没明白 回复 4# 李白vs苏轼
多谢指教.
斐波那契数列用数组来解决也许比递归快些.
#include <array.au3>
Local $time=TimerInit()
Local $nn=23
Local $arr
$arr=1
$arr=1
For $i=2 to $nn-1
$arr[$i]=$arr[$i-1]+$arr[$i-2]
Next
_ArrayDisplay($arr,TimerDiff($time)) 回复 6# 3mile
他的递归是有目的的,因为3种语言都是用递归,才能公平的比较速度 回复 1# magusneo
vbs是编译型语言,AHK和AU3都是解释型语言,在运行速度上肯定是编译型语言来的快! 回复 2# 魔导
我的,比你慢啊!
回复魔导
我的,比你慢啊!
xms77 发表于 2012-5-16 21:36 http://www.autoitx.com/images/common/back.gif
狗嘛,自然要比猫快些咯{:face (125):}
I3-540__8G啦 好像很深奥,留个脚印 回复 10# 魔导
猫快够慢啊!你说反了{:face (229):} 说反了不会吧 非常不错,学习了 小弟今天才知道还有一种ahk_l的脚本语言……
我印像中.VBS的文件可以直接在每台电脑上运行。
另外想问一下,VBS能不能编译成exe文件?
页:
[1]
2