I had a go at testing some raw allocation performance on an i5-7300 against kvec library https://github.com/attractivechaos/klib
Got some interesting results
C array, preallocated: 0.400 sec
C array, dynamic: 1.073 sec
C vector, dynamic (kv_push): 1.077 sec
C vector, dynamic (kv_a): 0.505 sec
C++ vector, preallocated: 0.402 sec
C++ vector, dynamic: 2.070 sec
dynamic : 1.23s
Rust system allocator
dynamic : 1.27s
Some initial conclusions
Preallocation is the way to go, no matter what the language; but even with dynamic arrays, Rust comfortably outperforms C++ and gets within 15% of C/kvec library.
The system allocator is possibly good for one off allocations where there’s not a lot of reallocation going on.