Costco Wholesale Corporation (COST -0.12%) and Wal-Mart Stores, Inc. (WMT 0.57%) have come to dominate U.S. retail. While that size is a testament to the company's historical success, lately it hasn't been much of advantage. Shopping habits are shifting as more people buy online, and Amazon.com has been rapidly outgrowing Costco and Wal-Mart lately, and even surpassed Costco in revenue last year.

Confronted with the threat of e-commerce, Costco and Wal-Mart have chosen different strategies. Costco has largely doubled down on the warehouse/membership model, opening new stores and resisting omni-channel services that have become common at other retailers, and the company just announced it would raise its membership fee this year. Wal-Mart, meanwhile, has transformed its strategy, acquiring Jet.com to get a jump-start in e-commerce and slowing down new store openings to invest instead in e-commerce, higher wages and better training, and improving its current store base. 

Let's take a closer look at these two retail behemoths to see which is the better buy today.

The entryway to a Costco store

Image source: Motley Fool.

The warehouse kingpin

Costco shares sold off following the company's recent earnings report as it missed estimates on all accounts. The warehouse retailer posted a respectable comparable sales increase of 3%, but earnings per share actually shrunk from $1.24 to $1.17 as merchandise costs rose 6%, wiping out a similar increase in sales.

The sell-off shows how Costco's premium valuation makes it vulnerable in a way that peers aren't. The warehouse chain has fared better than competitors recently as comparable sales continue to tick higher, but there have been pockets of weakness. Sales growth has slowed, and sales per square foot, a measure of how efficiently it's using its real estate, declined last year.

The company has resisted ramping up e-commerce operations, with CFO Richard Galanti telling investors last year that it would not implement a buy online-pick up in-store program because the company's goal was to bring customers into the store. Costco's "treasure hunt" model means the company often gets incremental sales from customers walking through the stores.

While other retailers are shuttering stores or holding back on growth, Costco has maintained its growth pace. The company has opened 13 warehouses through the first half of the year, and looks set to match last year's total of 32 for the full year, growing its store footprint by 4%. If sales per square foot continue to fall and same-store sales keep moderating, that strategy could become a problem.

The exterior of a Wal-Mart store

Image source: Wal-Mart

A whole new Wal-Mart

In recent years, Costco has skated relatively unscathed past the industry challenges, but the same hasn't been true for Wal-Mart. A few years, the retail giant was seeing same-store sales fall, and the chain often ranked at the bottom of customer satisfaction surveys. CEO Doug McMillion has sought to right those wrongs by raising wages, revamping employee training, investing to clean up and spruce up stores, and building out the company's e-commerce business.

As a result of those efforts, the company has now seen nine straight quarters of increasing comparable sales, reaching a peak of 1.8% in the fourth quarter. E-commerce sales growth has also recovered with the help of the Jet.com acquisition as online sales growth reached 29% in the recent quarter, up from single digits earlier in the year.

However, all those investments have cost the company on the bottom line. In fiscal 2017, Wal-Mart's operating income fell 5.6% to $22.8 billion, and adjusted EPS fell 6% from $4.59 to $4.32. The company expects earnings to be flat this year, forecasting EPS of $4.20-$4.40. For fiscal 2019, Wal-Mart expects earnings to grow 5%. In other words, Wal-Mart investors will have to be patient with the company's new strategy.

And the winner of the retail showdown is

Both retailers find themselves in challenging positions today as shopping patterns shift. Costco has the better momentum of the two as its stock has outperformed Wal-Mart in pretty much every timeframe over the last decade, but investors are paying up for its shares. They currently carry a P/E valuation of 32, pricier than almost any other big retailer. Wal-Mart trades at a valuation of just half of that at 16, and offers the better dividend yield at 2.9% versus just 1% for Costco.

While I'd be cautious with either one of these stocks given the challenging retail environment today, Wal-Mart looks like the better pick of the two. The company is aggressively shifting strategy to compete with Amazon and grow its business, and it's also cheaper and pays a better dividend. Costco shares, meanwhile, could slide if sales growth continue to decline.