Kobzol / hardware-effects

Demonstration of various hardware effects.
MIT License
2.82k stars 157 forks source link

Update misaligned-access.cpp #21

Open yuxineverforever opened 4 years ago

yuxineverforever commented 4 years ago

remove the cache effect (I try several times, not as obvious as directly write to memory). So that the misaligned access effect can be seen. (Correct me if I am wrong)

On Sandy Bridge:

Offset: 0, Time: 73.0
Offset: 1, Time: 76.0
Offset: 60, Time: 109.0
Offset: 61, Time: 108.4
Offset: 62, Time: 107.6
Offset: 63, Time: 109.2
Offset: 64, Time: 72.4

On SkyLake:

Offset: 0, Time: 40.0
Offset: 1, Time: 40.0
Offset: 60, Time: 61.0
Offset: 61, Time: 61.0
Offset: 62, Time: 61.0
Offset: 63, Time: 61.0
Offset: 64, Time: 40.0
Kobzol commented 3 years ago

Sorry for the long delay, I forgot about the PR :(

To be honest, in this example I wanted to show misaligned accesses directly inside the cache. Caches are generally very fast, so if you have a misaligned access in the cache (at least on x86), the difference w.r.t an aligned access should be bigger than if you need to go to memory.

On my Kaby Lake, the difference in cache seems to be about 1.5 - 2x slower, in memory it's about 1.25x slower.

I wonder why you have not observed the cache effect though. What times do you get with the cache misaligned access?