Costco (COST 0.17%) and Walmart (WMT 1.32%) are both resilient retailers that withstood Amazon's (AMZN -1.64%) assault as other brick-and-mortar retailers withered. Over the past decade, Costco's stock surged nearly 400% as Walmart's stock doubled.

Both retailers leveraged their scale to stay relevant. Costco's wholesale model enabled it to sell products at bulk rates while propping up its margins with membership fees. Walmart, which owns Costco's rival Sam's Club, matched Amazon's prices and turned its stores into a fulfillment network for online deliveries and pick-ups.

However, both stocks recently dipped along with the broader market amid concerns about the coronavirus crisis, the 2020 election, and other macro headwinds. Should investors accumulate shares of either retailer during the market downturn?

A shopper pushes a grocery cart down a supermarket aisle.

Image source: Getty Images.

The key differences between Costco and Walmart

Costco generated 98% of its revenue from product sales last quarter, and just 2% from membership fees. However, its membership fees accounted for 95% of its net profits.

Costco currently operates 785 warehouses. 546 are located in the United States and Puerto Rico, 100 are located in Canada, and the rest are located in other overseas markets. It achieved a membership renewal rate of 90.9% in the U.S. and Canada last quarter, and a worldwide renewal rate of 88.4%. Those high renewal rates give Costco a wide moat against Amazon, Walmart, and other retail challengers.

Walmart currently operates about 11,500 stores under 56 banners across 27 countries, and e-commerce websites in ten countries. Sam's Club has a presence comparable to that of Costco, with nearly 600 locations in the U.S. and over 200 international stores.

Walmart generated nearly 66% of its revenue from its U.S. stores last quarter. 24% came from its international stores, and 11% came from Sam's Club. Walmart generated most of its profits from its namesake stores and affiliated banners, and only 7% of its operating income came from Sam's Club.

Which company is growing faster?

Costco generated much stronger revenue growth than Walmart over the past decade, for two main reasons: Its smaller footprint gave it more room to open new stores (especially overseas), and its sticky membership ecosystem gave it room to raise its annual fees twice over the past nine years.

WMT Revenue (TTM) Chart

Source: YCharts

Walmart struggled to counter Amazon for several years before CEO Doug McMillion took the reins in 2014. McMillion implemented an aggressive turnaround plan for Walmart by bolstering its e-commerce capabilities, renovating its stores, opening smaller-format locations, and raising wages for its employees.

Costco didn't implement any aggressive spending plans like Walmart. Instead, its streamlined membership model churned out steady profits and allowed it to open new stores. As a result, Costco consistently generated stronger earnings growth than Walmart.

WMT Net Income (TTM) Chart

Source: YCharts

Wall Street expects Walmart's revenue and earnings to rise 3% and 4%, respectively, this year. Costco's revenue is expected to rise 7%, with 8% earnings growth. However, investors should take those forecasts with a grain of salt, since they don't fully account for the coronavirus outbreak in China, where both retailers operate stores.

Walmart operates 404 Supercenters, 26 Sam's Clubs, and eight Neighborhood Markets in China. It also owns 333 stores in Japan, which is struggling to contain an escalating outbreak. Costco operates one store in mainland China, 26 stores in Japan, and 16 in South Korea -- a market which Walmart failed to crack.

The valuations and verdict

Walmart trades at 23 times forward earnings and pays a forward dividend yield of 1.9%. It's raised that payout annually for 45 straight years. Costco has a higher forward P/E of 38 and pays a lower forward yield of 0.9%. It's hiked that dividend annually for 16 straight years.

Those valuations suggest that both stocks are a bit frothy relative to their growth estimates, which could be reduced if the macro headwinds worsen. I believe Costco's business model is stronger than Walmart's, but I think Walmart's lower valuation and higher dividend make it a safer stock in a wobbly market.