Impact of cpu cache lines验证

本文通过两个示例探讨了CPU缓存行对内存访问和性能的影响。Example 1表明,尽管第二个循环只完成了第一个循环约6%的工作量,但它们在现代机器上的运行时间相近,因为运行时间主要受内存访问而非乘法运算影响。Example 2深入解释了当步长超过数组中16个整数的倍数时,循环时间会因缓存行的利用而显著减少。了解缓存行对于某些程序优化至关重要。
摘要由CSDN通过智能技术生成

http://igoro.com/archive/gallery-of-processor-cache-effects/


此文提到

Example 1: Memory accesses and performance

How much faster do you expect Loop 2 to run, compared Loop 1?

int[] arr = new int[64 * 1024 * 1024];

// Loop 1
for (int i = 0; i < arr.Length; i++) arr[i] *= 3;

// Loop 2
for (int i = 0; i < arr.Length; i += 16) arr[i] *= 3;

The first loop multiplies every value in the array by 3, and the second loop multiplies only every 16-th. The second loop only does about 6% of the work of the first loop, but on modern machines, the two for-loops t

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值