Costco Wholesale (COST 0.33%) and Walmart (WMT 0.27%) have long been rivals.

They're both known for bargain pricing and primarily sell staples like groceries and paper products. The two companies operate with different business models, however. Walmart is mostly a conventional retailer, while Costco operates as a membership club, selling bulk products for bargain prices in exchange for a membership fee.

For investors, Costco and Walmart also have similar strengths. They both tend to outperform in bear markets as they sell products that consumers need no matter economy what the economy is doing, and are known for low prices.

Both stocks may have something to offer investors, but which of these is the better buy today? 

The parking lot in front of a Costco.

Image source: Costco.

Costco earns repeat business through great customer value

Parkev Tatevosian: Costco is arguably one of the best retailers in the world. The company has demonstrated an ability to deliver great value to customers while generating solid revenue and profit growth.

That's not an easy task to accomplish. It's relatively easy for a business to offer great value while losing money on the bottom line. A quick look around the public equity markets will reveal several companies that do just that. 

However, that does not describe Costco. The company has grown its revenue by a compound annual rate of 8.6% in the last decade. Over that same time, it increased earnings per share at a compound annual rate of 12.9%. Those are excellent figures by themselves. They appear even more impressive when you consider Costco has not posted an operating profit margin of more than 3.4% over those years.

In other words, Costco sells items at a lower profit margin and trusts that customers will return for more. As evidenced by the revenue and earnings growth, the strategy is working.

COST PE Ratio (Forward) Chart

COST PE Ratio (Forward) data by YCharts

Through prudent cost management, a more focused selection, and excellent execution, Costco delivers for investors and customers simultaneously. Fortunately, Costco's stock is not prohibitively expensive right now, trading at a forward-price-to-earnings ratio of 33.62. Investors might want to consider adding Costco stock to their shopping carts. 

A new Walmart

Jeremy Bowman: Compared to its rivals like Amazon and Costco, Walmart has a stodgy reputation. For years, it was criticized for underpaying employees and only focusing on low prices. However, the company has adapted to the times since then, and is much more than just a bargain-priced retailer.

Walmart has invested in omnichannel capabilities like grocery pickup stations in nearly all of its U.S. stores, and it's growing its e-commerce marketplace and monetizing it through a new advertising business.                                

Walmart is also the nation's largest grocer, and benefits from economies of scale in many of the categories in which it competes.

As a stock, Walmart offers a number of benefits, including a reliable dividend, a recession-proof business model, and steady growth. Better yet, the company seems to be beating Costco at its own game.

Sam's Club, Walmart's club chain, had long been a weak link for Walmart but that's changed. In the fourth quarter, Sam's Club posted comparable sales of 12.2% excluding fuel in the fourth quarter, compared to Costco at just 6.8% in its most recent quarter, showing it's gaining market share on its larger rival.

Walmart is also significantly cheaper than Costco, trading at a forward price-to-earnings ratio of just 22 compared to 36 for Costco, and the formerly staid retailer is seeing solid growth in e-commerce. It's opening up a high-margin revenue stream in advertising, and it's turned around Sam's Club.

Both Costco and Walmart are well positioned to outperform during the bear market, especially if the economy falls into a recession, but for investors, Walmart stock offers a much better value today.