I need some help benchmarking SoA vs AoS

maik klein via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 26 06:47:35 PDT 2016


I recently wrote an article an SoA 
https://maikklein.github.io/post/soa-d/

But now I wanted to actually benchmark SoA vs AoS and it is so 
much harder than I thought.

In DMD SoA basically always beats AoS by a huge chuck. SoA is 
always at least twice as fast compared to AoS.

But with LDC it is just really hard to get reliable results.

I have created a example without any dependencies

http://dpaste.dzfl.pl/877a925e0a33

dub run -b release --compiler=dmd

benchmarking complete access
AoS: 419 ms, 938 μs, and 2 hnsecs
SoA: 11 μs and 8 hnsecs
benchmarking partial access
AoS: 521 ms, 381 μs, and 3 hnsecs
SoA: 5 μs


dub run -b release --compiler=ldc

benchmarking complete access
AoS: 1 μs and 6 hnsecs
SoA: 1 hnsec
benchmarking partial access
AoS: 1 hnsec
SoA: 1 hnsec


The problem I have is that LDC always seems to optimize the 
functions too much. At least one function executes always in "1 
hnsec".

When I do manage do create an testcase where AoS and SoA have a 
reasonable time, then they are equally fast, no matter what I do.

What I wanted to see:

If I iterate over a collection and I always access all members, I 
would assume that AoS vs SoA should be equally fast.

If I iterate over a collection where the elements have a big size 
and I only access some members I would assume SoA to be much 
faster.

Any help tips are greatly appreciated.


More information about the Digitalmars-d-learn mailing list