It's pretty clear that today's economic woes are weighing on stocks. Major indexes have slipped into a bear market in recent times. And retailers, which are dependent on customer spending at a time when consumers' wallets are hurting, haven't escaped the gloom. But there are some exceptions, and one of those is warehouse giant Costco Wholesale (COST 1.09%).

Costco has continued to grow profit and revenue. Its shares aren't rising, but they're still outperforming the S&P 500, having slipped 15% year to date while the index has dropped 21%. Does this mean now is the time to buy Costco stock?

The challenge of higher inflation

Like other retailers, Costco is encountering higher inflation. In the recent fiscal fourth-quarter earnings report, management mentioned higher commodity prices, wages, and transport costs in particular. But it is still faring better in today's climate than many other retailers, for two reasons.

First, Costco generates a big percentage of its profit from membership fees. If you want to shop there, you have to pay $60 per year for a regular membership or double that for an executive membership that comes with some extra perks.

Costco's margins are much higher on membership fees than they are on merchandise. Memberships don't come with much expense for the company, but merchandise involves costs such as transport and storage. And since the company has a high membership renewal rate, it can count on this income annually. The latest worldwide renewal rate was more than 90%.

The second reason the retailer is holding up well is that it might be the place everyone wants to shop during tough economic times. You can buy many items in bulk and at rock-bottom prices. That's attractive to shoppers who are worried about their budgets.

Many of Costco's products are groceries or other essentials that shoppers can't do without no matter what the economy looks like. And once you've paid for a membership, it's in your best interests to keep coming back to do as much of your shopping as possible. All of these factors weigh in Costco's favor during an economic downturn.

Rising revenue and memberships

Costco's recent earnings report supports the idea that it can do well through times of trouble. Net sales for the fiscal fourth quarter rose more than 15% year over year. Membership also is on the rise, gaining more than 6% year over year to 118.9 million cardholders. Executive membership also is increasing, and that's important because executive members now account for almost 72% of Costco's sales globally.

And sales continue to climb. The company said September net sales rose 10% to more than $21 billion.

Now, let's talk about whether Costco's stock is a buy. It's true that it trades at a premium to other retailers such as Target or Walmart.

COST PE Ratio (Forward) Chart

COST PE Ratio (forward). Data by YCharts.

But Costco's strong membership model and its track record of gaining and holding on to those members make this stock worth that premium. Of course, it's possible that retailers that have suffered more than Costco will see a stronger rebound in share price once the economy improves. And that's OK.

Considering today's valuation, Costco might not offer your portfolio an enormous return in the near term. But over time, it could result in progressive and lasting gains. That's because its business model can be successful not only during tough economic times, but during strong periods, too. So now could be the right time to get in on this evergreen retail stock -- and hold on for the long term.