开发者

Finding the cache block size

开发者 https://www.devze.com 2023-02-18 22:45 出处:网络
How do I find the cache block size in Ubuntu, programmatically (with C++) or开发者_开发知识库 otherwise?You can find it in /proc/cpuinfo; cache size for the total size, and cache_alignment for the blo

How do I find the cache block size in Ubuntu, programmatically (with C++) or开发者_开发知识库 otherwise?


You can find it in /proc/cpuinfo; cache size for the total size, and cache_alignment for the block size.


One way is to fill an std::vector or just a plain array with random values, and do something simple, e.g. square each element in a loop. Then measure the execution time as a function of the vector length. You'll very clearly see a jump in the exec time once your vector does not fit into the cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消