[問題] 怎麼讓這段程式跑更快?

作者: Neisseria (Neisseria)   2013-12-27 10:43:23
這個函數的作用是
利用 dlocate -S $file 這個指令查詢 $file 屬於那個 Debian 套件
http://pastebin.com/K1hJZHLf 請賞光
利用 timeit 跑一次函數的速度約 0.1-0.2 秒之間
因為這個函數是一個中間的步驟
有時候會被執行很多次 結果整個指令執行起來很慢
完整的 script 已經可以用了 只是還很陽春
https://github.com/cwchen123/exe-deps.git
想問各位大大要怎麼加快這個 script 的速度?
[Update]:
後來在 script 中加入 cache 及 multi-threading
其中 cache 的方式用 memoized decorator
multi-threading 透過 multiprocessing
果然速度大有提升 接近 shell commands 的速度 偶而還會更快
不過用 ldd(1) 來查相依性 跟 Debian 套件中標示的相依性還是差一點
作者: jlhg (jlhg)   2013-02-27 13:43:00
multiple threads?
作者: uranusjr (←這人是超級笨蛋)   2013-02-27 15:58:00
看起來似乎是會對同一個 package 執行很多次一樣的指令或許可以考慮做個 cache

Links booklink

Contact Us: admin [ a t ] ucptt.com