How to find the size of the L1 cache line size with IO timing measurements?

后端 未结 8 673
深忆病人
深忆病人 2021-01-30 09:10

As a school assignment, I need to find a way to get the L1 data cache line size, without reading config files or using api calls. Supposed to use memory accesses read/write timi

8条回答
  •  孤城傲影
    2021-01-30 09:36

    I think it should be enough to time an operation that uses some amount of memory. Then progresively increase the memory (operands for instance) used by the operation. When the operation performance severelly decreases you have found the limit.

    I would go with just reading a bunch of bytes without printing them (printing would hit the performance so bad that would become a bottleneck). While reading, the timing should be directly proportinal to the ammount of bytes read until the data cannot fit the L1 anymore, then you will get the performance hit.

    You should also allocate the memory once at the start of the program and before starting to count time.

提交回复
热议问题