The Nasdaq Composite bear market has compressed the valuations of large, established companies and newer players alike. But not all stocks have taken a beating. Walmart (WMT 0.26%) and Costco Wholesale (COST -0.59%) remain two resilient dividend stocks that have managed to outperform the broader market. Walmart stock hit an all-time high on April 21, and Costco hit its all-time high on April 7 and almost broke past it on April 21.

Both stocks are holding up well, but there are indicators that one is the better value at the moment. Let's look at why Walmart may just be the better all-around dividend stock buy despite Costco having outperformed Walmart over the last decade.

A child being pushed in a shopping cart through a parking lot.

Image source: Getty Images.

Similarities between Walmart and Costco

The product mix and the business models of Walmart and Costco suggest that they cater to different consumers, but both companies have similar financials. After all the accounting is done, Walmart maintains an operating margin of 3.85% and Costco has an operating margin of 3.5%. The companies specialize in doing well on low margins. Each company is booking an operating income of less than four cents for every $1 in revenue despite selling different products and services. A low operating margin can be an indicator of a poorly run company. But in the case of Walmart and Costco, it's actually their biggest advantage because it allows them to offer more value and undercut the completion -- relying on a high volume to make up for the lower profits. 

Costco has been the better investment

Costco is one of those Peter Lynch-style stocks that has been hiding in plain sight for years yet continues to put up monster returns. In the last year alone, Costco stock has produced a 51% total return compared to 14% for Walmart and 1% for the S&P 500

COST Total Return Level Chart

COST Total Return Level data by YCharts.

Costco has beaten both Walmart and the S&P 500 over the last year, three years, five years, and over a 10-year time frame. Costco has produced a total return of 139% in the last three years, 250% in the last five years, and a staggering 723% in the last 10 years, whereas Walmart has actually lagged the S&P 500 -- producing a 231% total return in the last 10 years compared to the S&P 500's 263% total return.

Valuation comparison

Even though Walmart stock is trading at its all-time high, it still isn't that expensive. The company has a forward price-to-earnings (P/E) ratio of just 22.9, while Costco has a forward P/E ratio of 42.6. Walmart is also a Dividend Aristocrat, an S&P 500 component that has paid and raised its dividend annually for at least 25 consecutive years (47 years in Walmart's case). Walmart's dividend yield is 1.4%, which is about average for an S&P 500 stock. Costco has a low dividend yield of 0.65% (minimized in part by its strong stock price performance), but the company is known to pay periodic special dividends, such as its $10-per-share special dividend in 2020 and its $7-per-share special dividend in 2017.

Taking the P/E ratio comparison a step further though and something interesting comes to light. To see this, it can be helpful to think about what Costco's market cap would have to be for it to have the same P/E ratio as Walmart. If Costco had a P/E ratio of 22.9, it would have a share price of around $284 -- far less than its current price of around $555 per share and over a 50% drawdown from Costco's all-time high.

To justify its higher valuation, Costco needs to be growing at a much faster rate than Walmart. And to its credit, it is right now. Costco's revenue is up 52% in the last five years and 28% in the last three years, whereas Walmart has grown revenue by just 14.5% in the last five years and by 9.3% in the last three years. 

The concern is whether Costco can maintain the growth pace it needs to justify the high valuation. The bigger it gets, the harder it will be to do that. When it comes to finding a safe stock, issues like this need to be factored in.

Walmart looks like the better buy

In sum, Walmart and Costco are very similar businesses in terms of their operating margin. Walmart is a less expensive stock compared to Costco, but Costco is growing much faster than Walmart. What's nice about this comparison is that it's very clear to the investor what they are getting into. Walmart stands out as the safer choice and is a better all-around value, whereas Costco is a faster-growing company that should still do very well during times of inflation because it has an incredibly loyal customer base.

All told, the better safe stock to buy comes down more so to your personal preference as an investor. But given how cheap Walmart is, it strikes me as a better buy than Costco right now.