How to write a program in C to measure the speed of cache?

后端 未结 3 1421
小鲜肉
小鲜肉 2021-02-15 10:35

Write a program and try to compare(measure, if you can) the time of accessing data from main memory and cache.

If you can do that, then how to measure the speed of each

3条回答
  •  悲哀的现实
    2021-02-15 11:40

    Take a look at cachegrind-valgrind:

    Cachegrind simulates how your program interacts with a machine's cache hierarchy and (optionally) branch predictor. It simulates a machine with independent first-level instruction and data caches (I1 and D1), backed by a unified second-level cache (L2). This exactly matches the configuration of many modern machines.

    See tese nice questions they are somehow related:

    1. How do I programmatically disable hardware prefetching?
    2. How would you generically detect cache line associativity from user mode code?
    3. How to invalidate cache when benchmarking?

提交回复
热议问题