Stochastic wave-function method versus density matrix: a numerical comparison