Source Code [Benchmarking Sequential Iterators]
Posted on March 17th, 2008 at 23:39 by fr3@K

Source code used to produce results in my previous post is available for download here.

Please note that Boost.Date_Time is required in order to build it.

del.icio.us:Source Code [Benchmarking Sequential Iterators] digg:Source Code [Benchmarking Sequential Iterators] spurl:Source Code [Benchmarking Sequential Iterators] newsvine:Source Code [Benchmarking Sequential Iterators] furl:Source Code [Benchmarking Sequential Iterators] Y!:Source Code [Benchmarking Sequential Iterators] 黑米共享書籤:Source Code [Benchmarking Sequential Iterators] 推推王:Source Code [Benchmarking Sequential Iterators]
Benchmarking Sequential Iterators
Posted on March 16th, 2008 at 12:20 by fr3@K

這幾天有空, 終於把一項幾個月前就開始做的 benchmark 完成了.


看過好幾次有同事的 code, 明明就是使用 vector 來管理一串 element, 卻硬要把被管理的 element 的 pointer 取出, 以代替 vector 本身的 iterator 來做迭代. 有些同事說是不熟悉 iterator 的特性與操作方式. 這個理由很難讓人接受. 身為職業 C++ programmer, 標準的 container 與 iterator 是無論如何也要掌握住的技巧. 促成我搞這個 benchmark 的原因是有另外的同事跟我說, 取 pointer 出來迭代是因為 vector 的 iterator 比 pointer 慢很多, 並且是指數級別的差距!

在進行這項 benchmark 之前, 說以 vector 的 iterator 迭代比 pointer 慢, (起碼不會快過 pointer) 我絕對不會意外. 我猜大多數人也預期會看這樣的結果. 即便如此, 我還是很難想像其差異會大到如那位同事告訴我的這麼多. 因此我寫了個程式來 benchmark. 將 pointer 以及各種 STL 的 sequence container 的 iterator 做同樣的迭代, 把所使用的時間紀錄下來, 製作成表格以比較其間差異. 讓數字來說話.
(more…)

del.icio.us:Benchmarking Sequential Iterators digg:Benchmarking Sequential Iterators spurl:Benchmarking Sequential Iterators newsvine:Benchmarking Sequential Iterators furl:Benchmarking Sequential Iterators Y!:Benchmarking Sequential Iterators 黑米共享書籤:Benchmarking Sequential Iterators 推推王:Benchmarking Sequential Iterators