Shares of Costco Wholesale (NASDAQ:COST) have outperformed the broader market over the last decade. Members so love the warehouse club that when it introduces a 27-pound tub of macaroni and cheese for $90, it makes the news. 

Meanwhile, Walmart (NYSE:WMT) has been making a splash in other ways, such as with its strong e-commerce growth and its success with grocery delivery. Its stock, though, has underperformed the market in recent years.

But the question for investors is, based on these companies' performance, valuation, and likely futures, which one is the better buy today.

A woman hands pulling items out of a shipping box with the Walmart logo printed on the side.

IMAGE SOURCE: WALMART.

Costco has grown faster

Both of these retailers excel at sourcing merchandise at very low costs and reselling it at low prices. The latest results show Costco and Walmart performing comparably well, although Costco has been the faster-growing company in recent years. 

COST Revenue (TTM) Chart

COST Revenue (TTM) data by YCharts

In the most recent quarter, Costco reported worldwide comparable sales growth of 6.7%, excluding changes in gas prices and foreign currency. In the U.S., comp sales were up 7.2%. Walmart's U.S. comp sales rose a respectable 3.4%, marking the company's best first-quarter comp performance in nine years.

However, Walmart is flexing its muscles in e-commerce: Its online sales soared 37% year over year last quarter.  Even Sam's Club Q1 e-commerce sales growth of 28% was slightly better than Costco's adjusted growth of 25.5%. 

That particular success, though, in part explains Walmart's lack of operating income growth, as shown in the chart above. While its e-commerce revenues are growing, on the bottom line, that business is incurring losses as management invests heavily in the infrastructure, logistics, people, and new technologies it demands. It's a strategy similar to the one used by Amazon.com in its earlier stages -- the online retailer suffered massive losses for years before it eventually began turning slim profits. 

Lately, Costco has felt some pricing pressure from Sam's Club and other retailers, but its gross margin was still up 31 basis points in its fiscal second quarter. However, lower prices, even if they hurt margins in the short term, are a net positive for Costco and Walmart, because they have been the tools with which these companies have won over customers and driven sales for more than 30 years.

Walmart stock is cheaper

Costco scores a point on Walmart for its faster total growth, but Walmart scores a point for its faster online sales growth, and e-commerce is an increasingly important battlefield in the retail world. So how do the two compare in terms of valuation?

Metric Costco Walmart S&P 500
Trailing P/E 31.83 44.78 18.94
Forward P/E 31.11 21.50 17.54
Dividend Yield 0.95% 2.06% 1.86%

Data source: YCharts.

Keep in mind, Walmart's trailing price-to-earnings ratio is currently skewed due to the inclusion of India's Flipkart in the company's financial results -- Walmart closed its purchase of 81% of the online retailer in August. 

Costco's valuation has stretched toward the high end of its trading range over the last 10 years. It looks expensive for a company that analysts expect to grow earnings by 10.7% annually over the next five years. 

The forward P/E is a better measure of Walmart's value. While it has also drifted higher over the last few years, it represents a smaller premium to the S&P 500 index's average. But a forward P/E of 21.5 for a company that analysts expect to grow earnings by only 3.5% annually over the next five years doesn't seem like a great buy either.

Based on growth and valuation, neither stock looks compelling right now. However, there's one good reason why Walmart could surprise to the upside over the next 10 years.

Walmart is shaping the future of retail

Walmart's robust online growth reflects a company that is more technologically oriented than many investors probably realize. The company is winning big in grocery delivery, a service that has driven a meaningful amount of its e-commerce rise. And it's starting to test the use of self-driving cars to make those deliveries.  

Grocery pickup is now offered at 2,450 Walmarts in the U.S., and same-day grocery delivery is available from 1,000 stores. The retailer is also expanding grocery delivery in Mexico, China, and Canada. In this endeavor, it's much further ahead than even Amazon.com with its Whole Foods delivery service. 

Additionally, I like what Walmart is doing at its Store No. 8 testing lab. With this incubation arm, Walmart is experimenting and testing all kinds of forward-thinking technologies that could shape the future of retail. Most recently, Walmart launched the Intelligent Retail Lab to evaluate how artificial intelligence can help it better manage inventory and shelf space, which could increase stores' profits and deliver better value to customers. 

If I had to pick one, I would give the edge to Walmart for its efforts in e-commerce. Because of these initiatives, it's possible that analysts long-term growth estimates for Walmart could prove conservative.