Skip to content

Commit 6b3842b

Browse files
committed
bench: add SOA results
1 parent 751730e commit 6b3842b

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎bench/README.md‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,33 @@ Average sign time: 11 µs
9494
Average verify time: 30 µs
9595
```
9696

97-
## SOA Structs
97+
## SOA Structs (V2 cleanc only)
9898

99-
`bench_soa_structs.v` compares Array-of-Structs vs Struct-of-Arrays layout for a 16-field
100-
particle system (500k particles). Requires `@[soa]` attribute support.
99+
Compares Array-of-Structs vs Struct-of-Arrays memory layout for a 16-field
100+
particle system (500k particles). Uses V2's `@[soa]` attribute which auto-generates
101+
separate contiguous arrays per field for better cache utilization.
101102

102103
```
103-
v -prod -o /tmp/bench_soa bench/bench_soa_structs.v && /tmp/bench_soa
104+
./cmd/v2/v2 -prod -backend cleanc bench/bench_soa_structs.v -o bench/bench_soa_structs
105+
./bench/bench_soa_structs
104106
```
107+
108+
```
109+
build particles
110+
aos: 20 ms soa push: 125 ms soa indexed: 37 ms
111+
112+
sum x only
113+
aos: 19 ms soa: 12 ms speedup: 1.58x
114+
115+
sum x/y/z/life (4 of 16 fields)
116+
aos: 14 ms soa: 10 ms speedup: 1.40x
117+
118+
sum all 16 fields
119+
aos: 11 ms soa: 16 ms speedup: 0.69x
120+
121+
integrate position/velocity/life
122+
aos: 10 ms soa: 13 ms speedup: 0.77x
123+
```
124+
125+
SOA is 1.4x-1.6x faster for partial field access (fewer cache lines touched).
126+
When all fields are accessed or mutated, AOS wins due to less pointer indirection.

‎bench/bench_soa_structs.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const integrate_rounds = 20
1515

1616
@[soa]
1717
struct Particle {
18+
mut:
1819
x f32
1920
y f32
2021
z f32

0 commit comments

Comments
 (0)