メモリアクセス速度をちょっと実測
先日Core2にくらべるとPhenomは圧倒的に遅いとか言われたので、本当の所どうなのか計測してみる。
やったのは単純に4コア分のスレッドを用意してメモリアクセスするだけ。
- メモリ取得してからスレッドに分割
- スレッド分割した中でメモリ取得
- メモリ取得して一度触ってからスレッドに分割
メモリ取得してからスレッドに分割
コードがこれ。
#include <cstdlib> #include <boost/thread.hpp> #include <boost/progress.hpp> const int number_of_processors = 4; const int number_of_elements = 50 * 1024 * 1024; template < int SIZE > class MemoryAccess { private: int * ptr; public: MemoryAccess() : ptr( new int[SIZE] ) {} void operator () () { boost::progress_timer t; memset(ptr, 0, sizeof(int) * SIZE); } }; int main(void) { MemoryAccess < number_of_elements > ma[number_of_processors]; { boost::progress_timer t; boost::thread th0(ma[0]), th1(ma[1]), th2(ma[2]), th3(ma[3]); th0.join(); th1.join(); th2.join(); th3.join(); } return 0; }
結果がこれ。
1.63 s 1.62 s 1.60 s 1.52 s 1.65 s
スレッド生成を含む全体と、個別スレッドのアクセス時間はほとんど同じ。
アクセス速度は800[MB] / 1.65[s] = 485[MB/s]。
スレッド分割した中でメモリ取得
コードがこれ。
#include <cstdlib> #include <boost/thread.hpp> #include <boost/progress.hpp> const int number_of_processors = 4; const int number_of_elements = 50 * 1024 * 1024; template < int SIZE > class MemoryAccess { public: void operator () () { int * ptr = new int [SIZE]; boost::progress_timer t; memset(ptr, 0, sizeof(int) * SIZE); } }; int main(void) { MemoryAccess < number_of_elements > ma[number_of_processors]; { boost::progress_timer t; boost::thread th0(ma[0]), th1(ma[1]), th2(ma[2]), th3(ma[3]); th0.join(); th1.join(); th2.join(); th3.join(); } return 0; }
結果がこれ。
1.63 s 1.65 s 1.68 s 1.59 s 1.68 s
一番目とほぼかわらず。
アクセス速度は800[MB] / 1.68[s] = 476[MB/s]。
メモリ取得して一度触ってからスレッドに分割
コードがこれ。
#include <cstdlib> #include <boost/thread.hpp> #include <boost/progress.hpp> const int number_of_processors = 4; const int number_of_elements = 50 * 1024 * 1024; template < int SIZE > class MemoryAccess { private: int * ptr; public: MemoryAccess() : ptr( new int[SIZE] ) { memset(ptr, 0, sizeof(int) * SIZE); } void operator () () { boost::progress_timer t; memset(ptr, 0, sizeof(int) * SIZE); } }; int main(void) { MemoryAccess < number_of_elements > ma[number_of_processors]; { boost::progress_timer t; boost::thread th0(ma[0]), th1(ma[1]), th2(ma[2]), th3(ma[3]); th0.join(); th1.join(); th2.join(); th3.join(); } return 0; }
結果がこれ。
0.66 s 0.66 s 0.66 s 0.65 s 0.65 s
前二つよりかなり速くなっている。
アクセス速度は800[MB] / 0.66[s] = 1212[MB/s]。