Make your programs run faster by better using the data cache
huan

https://johnnysswlab.com/make-your-programs-run-faster-by-better-using-the-data-cache/

使用缓存来提高程序性能

  • 线性访问数据时,使用数组(相邻的元素会被一同放进缓存)
  • struct中经常访问的元素写在一起,增加同一缓存行的概率
  • 用数组代替指针,指针结构会降低缓存命中率

优化结构的大小

  • 行填充,struct大小为缓存行的倍数

矩阵运算

  • 使用行遍历,同一行中的元素缓存命中率高