I made the following implementation of the median in C++
and and used it in R
via Rcpp
:
// [[Rcpp::export]]
double median2
I'm not sure what "standard" implementation you would be referring to.
Anyway: If there were one, it would, being part of a standard library, certainly not be allowed to change the order of elements in the vector (as your implementation does), so it would definitely have to work on a copy.
Creating this copy would take time and CPU (and significant memory), which would affect the run time.