|
本帖最後由 rictirse 於 2013-2-19 00:48 編輯
chislide 發表於 2013-2-18 23:53 ![]()
已經可以校驗使用,但所耗時間是有點久,若能將所耗時間再縮短一點可能會更好。
AU的先天不足qq
無能為力xd
一樣跑浮點運算輸了C 大概有一千倍之多甚至更多
以最簡單的質數來舉例
N=10^9, 大約10秒內可以解出
au做一百萬位大概需要 2000s左右
兩者相差甚遠..
所以au的優勢在於,UDF很多使用起來簡單方便
基本上不要太艱深的命令都有現成的可以用用
開發容易與開發時間短,轉檔完成即可執行不需借助其他dll 等優勢
這邊借用一下EdisonX的code 來演示
[code=autoit]#include<array.au3>
#include <timers.au3>
const $n = 1000000
; -------------
$begin = _Timer_Init()
$Prime = Eratosthenes6n($n)
$td = _Timer_Diff($begin)
MsgBox(0, "", StringFormat("Find Prime Table Td = %lf msecs", $td))
_ArrayDisplay($Prime)
; ------------------------------------------
; byEdisonX
Func Eratosthenes6n($n)
Local $i, $j, $c=2, $gap, $i2
Local $p[$n+1]
Local $end = Int(Ceiling( Sqrt($n) ))
$gap = 2
$i = 5
While $i < $end
If Not $p[$i] Then
$i2 = $i+$i
For $j = $i*$i To $n Step $i2
$p[$j] = 1
Next
EndIf
$i+= $gap
$gap = 6 - $gap
WEnd
$i = 5
$gap = 2
$ret = "2 3 "
While $i < $n
If Not $p[$i] Then $ret &= $i & " "
$i += $gap
$gap = 6 - $gap
WEnd
$ret = StringSplit(StringTrimRight($ret, 1), " ")
return $ret
EndFunc[/code]
|
|