  We study the combined effects of measurements and unitary evolution on the
preparation of spin squeezing in an ensemble of atoms interacting with a single
electromagnetic field mode inside a cavity. We derive simple criteria that
determine the conditions at which measurement based entanglement generation
overperforms unitary protocols. We include all relevant sources of decoherence
and study both their effect on the optimal spin squeezing and the overall size
of the measurement noise, which limits the dynamical range of quantum-enhanced
phase measurements. Our conclusions are relevant for state-of-the-art atomic
clocks that aim to operate below the standard quantum limit.
