Walmart (WMT 1.17%) was struggling to keep pace with Amazon (AMZN -0.89%) when Doug McMillon became the retail giant's CEO in 2014. Its superstores were becoming showrooms for Amazon's online purchases, and its own e-commerce initiatives were weak.

But under McMillon, Walmart aggressively expanded its e-commerce ecosystem, matched Amazon's prices and delivery options, renovated its stores, leveraged its brick-and-mortar network to fulfill online orders, and boosted employees' wages.

Walmart also expanded overseas with a stake in China's JD.com and its acquisition of India's Flipkart. Those bold initiatives initially throttled its earnings growth, but they helped it keep pace with Amazon.

A concept delivery truck for Walmart.

Image source: Walmart.

Walmart's stock price has nearly doubled over the past five years and generated a total return of nearly 120% after factoring in reinvested dividends. But Amazon's stock has soared nearly 400% during the same period.

I compared these two retail giants last October, and I declared Amazon was still the better investment because it was buoyed by a higher-margin cloud business and its stock was still cheaper relative to its growth. Let's take a fresh look at both stocks to see if anything has changed.

The differences between Walmart and Amazon

Walmart generated 68% of its revenue from its namesake U.S. stores last quarter. Another 20% came from its international stores, while the remaining 12% came from its Sam's Club warehouse clubs.

The pandemic lit a fire under Walmart's digital business -- which offers in-store pickups, same-day deliveries, and next-day deliveries -- but it still relies heavily on its brick-and-mortar stores.

Walmart U.S. generated 12% of its revenue from its e-commerce business last quarter. Walmart International and Sam's Club attributed 16% and 9% of their sales to their digital channels, respectively.

An Amazon driver checks a delivery.

Image source: Amazon.

Amazon generated 59% of its revenue from its North American retail business, including Whole Foods Market, last quarter. It generated another 28% of its revenue from its international retail business, and 12% came from AWS (Amazon Web Services), the world's largest cloud infrastructure platform.

The pandemic generated strong tailwinds for both Amazon's online retail business, which surpassed 200 million Prime subscribers during the crisis, and AWS, which benefited from the rising usage of online services.

However, AWS also generated 47% of Amazon's operating profits, so its higher-margin cloud revenue actually supports its lower-margin retail businesses. This virtuous cycle enables Amazon to continue expanding its Prime ecosystem with discounts, cheap hardware devices, and digital perks. That unique strength gives Amazon a major advantage against Walmart and other retailers.

How fast is Walmart growing?

Walmart's revenue rose 7% to $559.2 billion in fiscal 2021, which ended this January. Its comparable-store sales rose 8.6% at Walmart U.S., with 79% e-commerce growth, as Sam's Club's comps increased 11.8%. Walmart International's sales, which aren't reported on a comparable basis, rose 1% with Mexico, Canada, and Flipkart driving most of that growth.

Its adjusted EPS rose 11%, and its free cash flow (FCF) surged 77% to $25.8 billion. It spent $8.7 billion of that total on buybacks and dividends.

In the first quarter of fiscal 2022, Walmart's revenue rose 3% year over year to $138.3 billion. Its comps rose 6% at Walmart U.S., with 37% e-commerce growth, as Sam's Club's comps grew 7.2%. Its international sales fell 8%, mainly due to a few divestments. Its adjusted EPS increased 43%.

For the full year, analysts expect Walmart's revenue to dip 1% against tough year-over-year comparisons to the pandemic. But they still expect its adjusted earnings -- buoyed by buybacks -- to rise 9%.

How fast is Amazon growing?

Amazon's revenue rose 38% to $386.1 billion in fiscal 2020 -- which aligns with the calendar year -- with 38% growth at its North American business, 40% growth at its international business, and 30% growth at AWS.

Its net income surged 84%, even as it racked up billions of dollars in pandemic-related expenses, and its EPS surged 82%. Its FCF, which it doesn't spend on buybacks or dividends, rose 20% to $25.8 billion. That impressive FCF growth gives Amazon plenty of room to expand its ecosystem with big investments.

That momentum continued in the first quarter of fiscal 2021. Amazon's revenue rose 44% year over year to $108.5 billion, its net income more than tripled to $8.1 billion, and its EPS soared 215%. Analysts expect its revenue and earnings to grow 27% and 34%, respectively, for the full year.

The valuations and verdict

Walmart's stock looks reasonably valued at 22 times forward earnings, but it faces much tougher post-pandemic comparisons than Amazon. Amazon's stock is pricier at 47 times forward earnings, but I believe the stickiness of its Prime ecosystem and the continued growth of AWS still justify that premium.

Therefore, I still believe Amazon will outperform Walmart this year, although the latter remains a rock-solid investment for long-term investors.