How do I find the cache block size in Ubuntu, programmatically (with C++) or otherwise?
Asked
Active
Viewed 4,159 times
3
-
Duplicate of http://stackoverflow.com/q/1922249/550514? – Chad La Guardia Mar 23 '11 at 06:12
-
@ChadLaGuardia I would say it is not a duplicate because that question is limited in scope to only C++. Here OP is open to methods outside of the specific language, such as a cli command. – The Unknown Dev Apr 10 '16 at 21:03
2 Answers
12
You can find it in /proc/cpuinfo
; cache size
for the total size, and cache_alignment
for the block size.

Mike Seymour
- 249,747
- 28
- 448
- 644
0
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.

ev-br
- 24,968
- 9
- 65
- 78