Spectral method for efficient computation of time-dependent phenomena in complex lasers