According to a study done in 2019 by the Frontier in Public Health “Orgasms with a partner were associated with the perception of favorable sleep outcomes, however, orgasms achieved through masturbation (self-stimulation) were associated with the perception of better sleep quality and latency. These findings indicate that the public perceive sexual activity with orgasm precedes improved sleep outcomes. Promoting safe sexual activity before bed may offer a novel behavioral strategy for promoting sleep.”
Besides helping you fall asleep at night, masturbating may promote a deeper sleep.