メモリ計測の続き

シングルスレッドで計測

最初にやれという話もあるが…。

#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;
        for (int i = 0; i < number_of_processors; ++i)
        {
            ma[i]();
        }
    }

    return 0;
}

結果がこれ。

0.05 s

0.05 s

0.06 s

0.05 s

0.21 s

アクセス速度は800[MB] / 0.21[s] = 3810[MB/s]。途中の時間表示をコメントアウトしても変わらず。
DDR2-800の理論値が6.4[GB/s]だから、それと比べて約半分しか出てないなぁ。