#!/bin/sh # investigate good cache usage sudo perf stat ./main -1 # investigate bad cache usage sudo perf stat ./main -2 # look at actual instruction and cache statistics sudo perf stat -e instructions -e cache-misses ./main -1 sudo perf stat -e instructions -e cache-misses ./main -2 # more detailed events like L1-dcache-loads and L1-dcache-load-misses # may be available on the system (sudo perf list) # investigate which lines of code cause the problem sudo perf record -e cache-misses ./main -2 sudo perf report