Insomniacs: If you think taking a long run today will make you sleep better tonight, think again.

While exercise has long been a prescription for insomnia, new research suggests that exercise does not immediately translate into a better night’s sleep — unless you stick with it for months.

A study published Thursday in the Journal of Clinical Sleep Medicine found that aerobic exercise can lead to more rest at night for people who suffer from sleep problems, but only if they maintain an exercise regimen for roughly four months.

“Exercise isn’t a quick fix. … It takes some time and effort,” said the study’s lead author, Kelly Glazer Baron, director of the behavioral sleep program at Northwestern University’s Feinberg School of Medicine.

For the study, Baron and her researchers looked at the daily activities and sleep logs over a 16-week period for nearly a dozen women, ages 57 to 70, who were wrestling with insomnia — defined as having difficulty falling asleep or staying asleep as well as having trouble functioning because of the lack of sleep.

The researchers discovered that only after months of persistent exercise did the patients begin to experience more restful nights. Over time, the women began sleeping about 45 minutes more a night on average.

“The effects were huge when they stuck with it,” Baron said.

Why exactly does it take so long for exercise to result in more restful nights?

“Patients with insomnia have a heightened level of brain activity, and it takes time to reestablish a more normal level that can facilitate sleep,” said Phyllis Zee, a neurology professor and another author of the study. “Rather than medications, which can induce sleep quickly, exercise may be a healthier way to improve sleep because it could address the underlying problem.” 

Researchers also found that the relationship between sleep and insomnia runs in both directions. While sustained exercise can help people sleep better, a bad night’s rest can leave people less motivated to exercise. 

“Sleep deprivation doesn’t change your physical capacity, but it changes your perception of how hard the exercise is,” Baron said. “You feel more exhausted.” 

Past research suggests that the timing of exercise also might affect a person’s sleep. The National Sleep Foundation, for instance, recommends exercising at least three hours before bedtime, in part to allow the body to cool down. 

Baron said insomniacs should take two key messages from Thursday’s findings: Don’t give up on an exercise plan if you aren’t seeing results right away. And find the inspiration to exercise even on days you might not feel like it. 

“Write a note on your mirror that says ‘Just Do It!’ ” she said. “It will help in the long run.”