  We study the estimation of the overlap between two unknown pure quantum
states of a finite dimensional system, given $M$ and $N$ copies of each type.
This is a fundamental primitive in quantum information processing that is
commonly accomplished from the outcomes of $N$ swap-tests, a joint measurement
on one copy of each type whose outcome probability is a linear function of the
squared overlap. We show that a more precise estimate can be obtained by
allowing for general collective measurements on all copies. We derive the
statistics of the optimal measurement and compute the optimal mean square error
in the asymptotic pointwise and finite Bayesian estimation settings. Besides,
we consider two strategies relying on the estimation of one or both the states,
and show that, although they are suboptimal, they outperform the 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.
