We develop a simple method for measuring the electron spin relaxation times $T_1$, $T_2$ and $T_2^*$ in semiconductors and demonstrate its exemplary application to $n$-type GaAs. Using an abrupt variation of the magnetic field acting on electron spins, we detect the spin evolution by measuring the Faraday rotation of a short laser pulse. Depending on the magnetic field orientation, this allows us to measure either the longitudinal spin relaxation time $T_1$ or the inhomogeneous transverse spin dephasing time $T_2^*$. In order to determine the homogeneous spin coherence time $T_2$, we apply a pulse of an oscillating radiofrequency (rf) field resonant with the Larmor frequency and detect the subsequent decay of the spin precession. The amplitude of the rf-driven spin precession is significantly enhanced upon additional optical pumping along the magnetic field.