4 ms·
It's still marginally slower at 760 milliseconds, give or take (I suspect that's because major heap allocations are generally more expensive than nursery alloca
by rbehrends 9y ago
It's still marginally slower at 760 milliseconds, give or take (I suspect that's because major heap allocations are generally more expensive than nursery allocations). That said, in that case I could also use `List.init` and be even faster.
The problem is that often you don't know exactly how much memory you'll preallocate. This is where in (say) C++, you'll resort to an arena or pool allocator; a GC with a bump allocator will give you what is essentially a smart arena allocator by default for your temporary allocations.