Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何以编程方式(使用 C++)或其他方式在 Ubuntu 中找到缓存块大小?
你可以在/proc/cpuinfo; cache size对于总大小和cache_alignment块大小。
/proc/cpuinfo
cache size
cache_alignment
一种方法是std::vector用随机值填充一个或只是一个普通数组,然后做一些简单的事情,例如对循环中的每个元素进行平方。然后测量执行时间作为向量长度的函数。一旦您的向量不适合缓存,您将非常清楚地看到执行时间的跳跃。
std::vector