Izza
Izza

Reputation: 2419

Finding the cache block size

How do I find the cache block size in Ubuntu, programmatically (with C++) or otherwise?

Upvotes: 4

Views: 4846

Answers (2)

Mike Seymour
Mike Seymour

Reputation: 254741

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

Upvotes: 14

ev-br
ev-br

Reputation: 26100

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.

Upvotes: 0

Related Questions