My guess is that it would be hard to distinguish them in performance.
It’s difficult but I guess using unsafeThawArray
is OK and will be faster than both version 1 and version 2.
It would indeed be faster, but that would mean the array is modified in-place, so then you would not be able to safely use the old array after mapping.
That’s a good guess, but from some preliminary benchmarks I get a difference of about 20% for some inputs. Although the benchmark is very fragile, so I still need to investigate it in more detail.
I’m getting pretty consistent results like this:
So Version 1 seems to be up to 25% faster than Version 2 when the input size is around 4,000 elements and then slowly decreases until there is not much of a difference when the input size is around 1,000,000 elements.
Interesting that the first version is faster for short arrays. I think looking at Core would be informative.