They both need to make a copy because the size of the array changes. None have an advantage.
So yes, for huge arrays there are probably tweaks that could be done to optimize the code for speed and operate more in-place. 🙂
The sorting is about O(NlogN), so will be dominant for large arrays because all the other stuff is O(N). If we expect most elements to be different, we could just preallocate the final array dimension the same as the input array (worst case scenario, all elements different!) and then use "replace array subset" to fill with data, followed by a final trimming to the actual size. We could also do a quick "run" through the array and count the number of transitions, then preallocate the output array at the correct size before doing the statistics. This might be better for cases where the final output is significantly smaller than the input (=many duplicate elements). There are many possibilities. 😄
For smaller arrays, the given code should be fine.