We study the estimation of the overlap between two Haar-random pure quantum states in a finite-dimensional Hilbert space, given M and N copies of them. We compute the statistics of the optimal measurement, which is a projection onto permutation-invariant subspaces, and provide lower bounds for the mean square error for both local and Bayesian estimation. In the former case, the bound is asymptotically saturable by a maximum likelihood estimator, whereas in the latter we give a simple exact formula for the optimal value. Furthermore, we introduce two LOCC strategies, relying on the estimation of one or both the states, and show that, although they are suboptimal, they outperform the commonly-used swap test. In particular, the swap test is extremely inefficient for small values of the overlap, which become exponentially more likely as the dimension increases. Finally, we show that the optimal measurement is less invasive than the swap test and study the robustness to depolarizing noise for qubit states.