Hospitals are one of the worst places to try to get a good night's sleep, just when you need it the most. And though many have tried to muffle the noise of beeping monitors and clattering carts, the noise remains a big problem for many patients.

But what if we looked at a night in the hospital as a long overseas flight? As you settle in, they hand out eye masks and earplugs. And you cleverly brought along melatonin, the sleep-regulating hormone sold at drugstores everywhere.

Researchers in China tested just that, and found that eye masks, earplugs and melatonin all helped. But melatonin helped the most.

They tested them by creating a fake intensive care unit with noise and lights, and getting 40 healthy adults to sleep in it. With the noise and lights off, their melatonin levels rose sharply until about 4 am, which is typical of a normal sleep cycle. They snoozed happily.

But with the noise and lights on, melatonin levels tanked. The people said they slept poorly and were anxious.

OK, on with the eye mask. The volunteers were given their choice of eye masks and earplugs and hit the hay. They fell asleep faster, were less likely to wake up, and arose saying they slept better and were less anxious.

Sounds like a win. But many people didn't like the earplugs, saying they were uncomfortable or claustrophobic. And the earplugs didn't do enough to muffle sounds.

Now for the melatonin. The volunteers took 1 mg at bedtime and said that did the best job of improving sleep quality and reducing anxiety. They also woke up less often during the night. And the melatonin level in their blood was much higher than while wearing eye masks or earplugs.

The researchers also tested a placebo pill, but it improved sleep only slightly.

People in an intensive care unit are very ill, the researchers note, and eye masks and earplugs might not be enough to restore normal biological sleep patterns. The study was published Thursday in the journal Critical Care.

And melatonin isn't risk free. It isn't recommended for people with high blood pressure or depression. And it can increase immune function, which can be problematic for people with autoimmune diseases or transplants.

But it would be nice if hospitals handed out eye masks and earplugs along with those no-slip socks, wouldn't it?

Copyright 2016 NPR. To see more, visit http://www.npr.org/.