1
在Rust by Example #36中,在命令式和函數式中都計算達到極限的奇數整數之和。函數式編程中的開銷
予分離這兩個出並增加了上限10000000000000000和計時的結果:
祈使式:
me.home:rust_by_example>time ./36_higher_order_functions_a
Find the sum of all the squared odd numbers under 10000000000000000
imperative style: 333960700851149440
real 0m2.396s
user 0m2.387s
sys 0m0.009s
功能樣式:
me.home:rust_by_example>time ./36_higher_order_functions_b
Find the sum of all the squared odd numbers under 10000000000000000
functional style: 333960700851149440
real 0m5.192s
user 0m5.188s
sys 0m0.003s
功能版本運行速度較慢並且編譯所需的時間也稍長一些。
我的問題是,什麼導致功能版本變慢?這是功能風格所固有的,還是由於編譯器沒有進行優化而導致的?
您必須編譯優化(rustc -O ...) – Arjan 2014-09-02 17:57:21
當然。功能風格現在略快。 – user2664470 2014-09-02 18:29:03