I'll admit it. I blew it when I bought shares of Select Comfort (NASDAQ:SCSS) a couple of years ago, after a few nights of peaceful slumber in my new Sleep Number bed.

Yet that was when the company was growing, coming out consistently profitable, and making other mattress rivals, such as pressure-relieving Tempur-Pedic (NYSE:TPX) and innerspring titan Sealy (NYSE:ZZ), seem like slowpokes in comparison.

I still love my bed. I just hate the stock. I should have sold it at the first whiff of deteriorating fundamentals, but I guess I slept through that, too.

Anyway, my point is that I was surprised to see Select Comfort thrive in yesterday's bloodbath of a market, after posting its second-quarter results. Shares rose by as much as 13% after the company posted better-than-expected results, before getting caught in the market's spiral. It still managed to close out the day with a 4% uptick.

The key phrase there is "better than expected," because, on an absolute basis, the quarter was atrocious.

Net sales fell by 15% to $152.1 million. Comps fell by a steep 20%, and that's after falling by 14% during last year's second quarter. In other words, sales at the store level are coming in 31% below where they were two years ago. The company posted a loss of $0.15 a share, a reversal from a year-ago profit.

You know how some companies are riding their online sales growth to offset retail weakness? That's not Select Comfort, where e-commerce actually dragged down performance with a head-scratching 27% year-over-year plunge.

Yes, Select Comfort is that ugly these days. However, the stock rallied since Wall Street had been looking for a $0.17-per-share deficit. After missing analyst expectations in the two previous quarters, Select Comfort finally scored a relative victory.

The company also offered up encouragement -- it's positioned to return to profitability during the second half of the year. Select Comfort is doing all of the right things. It's cutting costs, closing stores, and even raising prices. Yes, it's true -- the average mattress sold for $1,831 during the quarter, a lot more than the $1,688 it averaged a year ago. The grim but logical implication, of course, is that mattress-unit growth fell by more than the 20% dip in comps.

Select Comfort understands the challenges of this tricky environment. It is dusting off a new marketing campaign, introducing a new mattress, and even emphasizing its lower-priced accessories, such as pillows, in an effort to appeal to penny-pinching consumers.

It's not Select Comfort's fault that the economy hit the skids and that it began outfitting beds in Winnebago (NYSE:WGO) RVs just as soaring gas prices and stingy financing were nibbling at that niche. However, Select Comfortcan be held accountable for yielding market share to its peers.

Select Comfort may have finally bottomed out earlier this week. But at least if you fall out of bed, you're not all that far from the floor.

More bedtime reading:

Select Comfort is a former recommendation for Motley Fool Hidden Gems subscribers.

Longtime Fool contributor Rick Munarriz thinks a good night's sleep is better than a balanced breakfast to start the day off right. He does own shares in Select Comfort.  He is also part of the Rule Breakers newsletter research team, seeking out tomorrow's ultimate growth stocks a day early. The Fool has a disclosure policy.