The relentless growth of e-commerce has wiped away a huge swath of the traditional retail industry in recent years. Yet not every retailer will succumb to this unfortunate fate.

For example, Costco Wholesale (COST 0.64%) and Walmart (WMT -0.52%) have found ways to not just survive, but thrive in this intensely competitive environment, and they've delivered solid gains to their investors along the way.

But which of these retail giants' stock is the best buy now for investors? Let's compare them on a few key fronts.

Check out the latest earnings call transcript for Costco and Walmart.

Strategy

Walmart has wisely prioritized its e-commerce and omnichannel initiatives in recent years. It acquired Jet.com in 2016, and shortly thereafter placed the online retail upstart's founder and CEO, Marc Lore, at the helm of its e-commerce operations. Since then, Walmart has broadened its online selection, improved its free shipping options, and strengthened its fulfillment network.

A computer keyboard button labeled add to cart

Walmart is adapting to the e-commerce revolution better than perhaps any other big box retailer. Image source: Getty Images.

Walmart also positioned its industry-leading grocery business at the core of its omnichannel strategy. By steadily rolling out grocery pickup across its massive store base, and expanding its delivery offerings, Walmart has sought to add more value and offer more convenience to store-goers and online shoppers alike.

Together, these tactics have fueled solid gains in Walmart's e-commerce sales, while also helping to drive traffic and boost sales at its stores.

Costco, in contrast, has maintained a laser-like focus on its in-store operations. The warehouse store operator derives the majority of its profit from membership fees; that model allows it to offer goods at prices that even online competitors find difficult to match. Costco also limits its selection and changes it often. This creates a treasure hunt-type shopping experience that helps to drive strong repeat traffic to its stores.

All told, Costco is one of the best run traditional retailers -- if not the best. But Walmart's heavy e-commerce investments reflect a more forward-thinking approach. And with retail sales increasingly migrating to online channels, its leadership in this area is likely to be an important competitive edge in the years ahead.

Advantage: Walmart

Financial strength

Metric

Costco Wholesale

Walmart 

Revenue

$144.8 billion 

$514.4 billion

Operating income

$4.5 billion 

$22 billion

Operating cash flow

$5.9 billion 

$27.8 billion

Free cash flow

$3.1 billion 

$17.4 billion

Cash & investments

$8 billion 

$7.7 billion

Debt

$6.5 billion 

$58 billion 

Data sources: Morningstar, company filings.

Costco clearly has the stronger balance sheet, with $1.5 billion in net cash compared to Walmart's $51 billion in net debt. However, Walmart generated more than five times as much free cash flow as Costco in the past year. This strong cash production allows Walmart to easily service its debt while simultaneously rewarding investors with bountiful dividends and share repurchases. And if it chose to, Walmart could pay down its debt over time. As such, Walmart has the edge here.

Advantage: Walmart

Growth

Walmart may be the superior cash generator, but Costco is growing much more rapidly. Over the past five years, Costco's revenue, operating cash flow, and free cash flow growth have all drastically exceeded those of Walmart.

COST Revenue (TTM) Chart

COST Revenue (TTM) data by YCharts

Moreover, Costco's sales and profit growth are likely to continue to surpass Walmart's in the coming years.

Wall Street expects Costco's revenue to rise by 8% in 2019 and 6.7% in 2020,  fueled by new store openings and strong same-store sales growth. Additionally, analysts estimate that Costco's earnings per share will increase by 10.6% annually  over the next five years, driven by continued growth in its membership fees.

Walmart, meanwhile, is projected to grow its sales by less than 3% both this year and next,  as it focuses more on store remodels rather than new openings.  Moreover, Walmart's EPS is forecast to rise by less than 4% annually over the next half-decade, as its e-commerce investments continue to weigh on its profitability.

Advantage: Costco

Valuation

Metric

Costco Wholesale

Walmart

Price-to-Sales Ratio

0.66 

0.56 

Price-to-Free-Cash-Flow Ratio

31.07 

16.61 

Forward Price-to-Earnings Ratio

25.84 

19.87 

Data source: Yahoo! Finance.

Across all three of these common valuation metrics, Walmart's shares are significantly less expensive than those of Costco. This is to be somewhat expected, given Costco's higher expected earnings growth rate. Still, Walmart's stock is currently 47% and 23% cheaper based on free cash flow and expected earnings, respectively. That makes it the better bargain. 

Advantage: Walmart 

The winner is...

Costco may be growing faster, but Walmart's e-commerce success, superior cash flow production, and more attractively priced stock make it the better investment today.