For decades, Costco Wholesale Corporation (COST 0.12%) and Wal-Mart Stores, Inc. (WMT 0.31%) have defined the opposing poles of American retail.

Costco Wholesale has concentrated its business on the coasts, favoring higher-income markets with its membership model, which charges customers $60/year for the privilege of shopping in its cavernous, bargain-bin warehouse. Wal-Mart, on the other hand, has been most successful in the rural interior of the country in regions like the South and the Midwest, where its everyday low prices model has made it the dominant retailer.

The two have also embodied different approaches to human resources. Costco is regarded as one of the best retailers to work for in the country. Wages start at $13/hour, and the average hourly worker earns $21/hour. Wal-Mart, by contrast, has long been embroiled in controversy around its hiring practices and has developed a reputation for abusive employment tactics and union-busting, though in recent years CEO Doug McMillon has tried to make amends. He raised the base wage to $10/hour, setting off a wave of wage hikes in retail, and has implemented better training practices in order to boost employee retention.

The sign on the front of a Wal-Mart Neighborhood Market

Image source: Wal-Mart.

Both stocks took a hit last week when Amazon (AMZN 0.20%) said it would buy Whole Foods Market, marking a shot across the bow in the grocery industry as both Wal-Mart and Costco, despite being mass merchandisers, derive a majority of their sales from groceries.

Over the past five years, Costco has outperformed Wal-Mart by a considerable margin, but even it has fallen short of the S&P 500, which may be a sign of the broader struggles in retail.

COST Chart

COST data by YCharts

Let's take a closer look at what each stock has to offer today to see which is the better buy.

Adapting quickly

Wal-Mart isn't the same old Wal-Mart anymore. For years, the world's largest retailer could just open new supercenters across the country and pad its income statement as economies of scale made it the lowest cost provider, elbowing out independent stores.

However, the rise of Amazon and e-commerce has threatened the retail giant like nothing before. Wal-Mart saw its revenue decline in 2015 for the first time in at least 45 years -- its entire publicly traded history -- but the retailer has made a number of changes since then. In addition to the wage hikes, CEO McMillon has invested in cleaning up stores to improve customer satisfaction and built out hundreds of grocery pick-up kiosks, which helped drive U.S. e-commerce sales up 63% in its most recent quarter.

Most importantly, the retailer acquired Jet.com last year for $3.3 billion, helping accelerate its e-commerce ambitions substantially. Under the guidance of Jet.com founder Marc Lore, who now runs the company's U.S. e-commerce operations, Wal-Mart has begun offering free two-day shipping on orders over $35, as well as a discount on certain items if customers pick them up in a store. Lore has also guided five acquisitions of smaller e-commerce businesses, the most recent of which was Bonobos for $310 million, as he intends to build out a stable of higher-end brands for Jet.com.

The efforts seem to be yielding positive results, as the company has posted eleven straight quarters of comparable sales growth in the U.S. After investing in higher wages and store improvements caused earnings per share to fall for three years in a row, Wal-Mart expects to return to profit growth next year.

Sticking with what works

While Wal-Mart has made significant efforts to adapt to e-commerce, Costco mostly resisted calls to transform its business. Costco's model lends itself poorly to online shopping as it relies on customers coming in and buying bulk goods that would be difficult to ship. CFO Richard Galanti also said the retailer doesn't offer services like buy online/pick-up in store because he wants to get customers in the store so that they'll make impulse purchases, as Costco's product selection is always changing.

Thus far, that strategy appears to be working -- Costco's comparable sales are better than those of almost any other retailer. In its most recent quarter, the key figure increased 5% in the U.S. and globally. 

However, Costco stock sold off sharply following the announcement of the Amazon-Whole Foods deal, falling more than 10% since then. Wall Street sees the warehouse retailer as a big potential loser in the deal. Unlike Wal-Mart, Costco relies on a membership model much like Amazon Prime, and now that Amazon has a major supermarket chain under its wings, it's likely to step up efforts in grocery delivery and either bundle that with Prime or lower prices on AmazonFresh. Prices at Whole Foods are also expected to come down. Since Costco and Amazon tend to compete for a similar customer base, affluent consumers on the coasts, Costco may feel the hurt more than any other retailer.

And the winner is...

Costco's business has been the better performer of late as it's delivered strong comparable sales and profit growth, but investors will also pay a higher price for the stock. The warehouse retailer now trades at a price-to-earnings (P/E) ratio of 27.7, compared to Wal-Mart's 17.2 P/E. Wal-Mart offers a better dividend yield at 2.7% versus 1.2% for Costco, but a fair comparison is difficult as Costco has paid three special dividends since 2012.

It's a close call to determine the better buy, but I'd rather invest in Wal-Mart if I had to choose between the two. The company is making positive changes to challenge Amazon and grow e-commerce sales, while Costco has mostly relied on the historical success of its membership model and seems particularly threatened by the Whole Foods acquisition. Costco is also significantly more expensive, and I don't think it's worth the premium over the world's largest retailer. Wal-Mart should outperform the warehouse giant as long as it can return to profit growth as it projects. It's the better buy today.