mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-20 18:18:31 +00:00
c90a028456
Create 334-line benchmark validating Dict vs type-stable field performance claims
from zero_allocation_fields.md design document.
Benchmark structure:
- Lines 1-18: Header and expected results summary
- Lines 20-64: Field type definitions and mock element setup
* AbstractField{T}, ConstantField{T}, NodalField{T}
* Accessor functions: value(f::ConstantField), value(f::NodalField, node_ids)
* Mock element with 8-node connectivity
Benchmark suite (5 tests):
1. Constant field access (lines 70-92): Dict["key"] vs value(field)
Expected: ~50× faster, 0 allocations
2. Nodal field access (lines 97-120): Array slicing vs @view
Expected: ~50× faster, 0 allocations
3. Interpolation without cache (lines 126-170): Type-unstable vs typed
Expected: ~16× faster with fewer allocations
4. Interpolation with cache (lines 176-205): Zero-allocation target
Uses InterpolationCache struct with pre-allocated result buffer
Expected: 0 allocations, maximum speedup
5. Assembly loop (lines 211-261): 1000 elements, Dict vs NamedTuple
Expected: 10-100× faster (hoisted constant access)
Validation section (lines 267-328):
- Compares actual results to claimed performance
- ✅/⚠️ status for each benchmark
- 10× speedup threshold (conservative vs claimed ~50×)
- Zero allocation verification for cached operations
Key insights:
- Type stability eliminates runtime dispatch overhead
- @view and caches achieve zero allocations
- Hoisting invariant access provides massive speedup
- Validates NamedTuple + typed fields design for v1.0
Dependencies: BenchmarkTools, LinearAlgebra
Executable: #!/usr/bin/env julia (chmod +x ready)