Amazon (NASDAQ:AMZN) and Walmart (NYSE:WMT) are two of the largest retailers in the world. Amazon operates its marketplace in dozens of countries, and its top markets include the U.S., Germany, the UK, and Japan.

Walmart operates 56 different banners across 27 countries. Its top market is the U.S., but it also owns the Indian e-commerce giant Flipkart and a major stake in JD.com, China's biggest direct retailer.

Ten years ago, Amazon seemed destined to disrupt Walmart's core business. Amazon offered lower prices, and it turned Walmart's stores into showrooms for online purchases.

But under CEO Doug McMillon, who took the helm in 2014, Walmart aggressively expanded its e-commerce ecosystem, matched Amazon's prices and delivery options, fulfilled online orders with its stores, and boosted employees' wages and benefits.

An Amazon delivery driver checks an order.

Image source: Amazon.

Those turnaround efforts initially reduced Walmart's profits, but they helped the retailer evolve and counter Amazon. As a result, Walmart's stock rallied nearly 150% over the past five years -- but it couldn't match Amazon's gain of over 430% during the same period.

Will Amazon continue to outperform its top brick-and-mortar rival over the long term? Let's take a fresh look at both companies to decide.

Amazon enjoys 2 key advantages against Walmart

Amazon consistently generates stronger revenue and earnings growth than Walmart for two main reasons.

First, Amazon generates most of its operating profits from Amazon Web Services (AWS), the world's largest cloud infrastructure platform. AWS' profits subsidize the growth of Amazon's lower-margin North American business and its unprofitable international business. Two years ago, AWS' rising profits enabled Amazon's trailing 12-month operating margins to surpass Walmart's:

AMZN Operating Margin (TTM) Chart

Source: YCharts

That's why Amazon can consistently sell its products at low prices while expanding its Prime ecosystem with low-margin or loss-leading devices like the Kindle, Fire TV, and Echo.

Second, Amazon's Prime ecosystem becomes stickier with new devices, delivery services, and digital perks -- which locks in shoppers and widens its moat against rivals like Walmart. Amazon surpassed 150 million Prime subscribers globally at the end of 2019, and that figure will likely climb even higher this year.

But Walmart also has advantages against Amazon

Walmart's main advantage against Amazon is its network of about 11,500 stores worldwide. Walmart's store count surpasses Amazon's number of fulfillment centers by a wide margin, and it's using many of those locations as fulfillment centers and pickup locations for online orders.

Walmart also recently struck back against Amazon Prime with Walmart+, a $98-per-year plan that bundles together unlimited free deliveries; fuel discounts; and access to the Scan & Go service, which lets shoppers scan products to instantly pay without going through the checkout line or self-checkout kiosks.

It's unclear if Walmart+ will pull enough shoppers away from Amazon Prime, which costs $119 per year, but it indicates Walmart recognizes Prime as the core of Amazon's "Death Star" approach to retail.

Which company is growing faster?

Walmart's total revenue grew 2% last year, with 2.8% comparable-store sales growth at Walmart U.S., 0.7% comps growth at Sam's Club (excluding fuel), and a 37% spike in e-commerce sales in the U.S. Its adjusted earnings per share (EPS) rose 12%.

Walmart shoppers on Black Friday

Image source: Walmart.

In the first six months of fiscal 2021, Walmart's revenue rose 7% year over year, as the COVID-19 crisis sparked robust sales of household essentials. Its combined U.S. comps at Walmart and Sam's Club (excluding fuel) rose 10.3% in the first quarter and 9.9% in the second quarter.

Walmart's U.S. e-commerce sales surged 74% year over year in the first quarter and accelerated to 97% growth in the second quarter. Its margins were pressured by COVID-19 costs, online fulfillment expenses, and sales of lower-margin products, but its adjusted EPS still grew 5%. Analysts expect its revenue and earnings to rise 5% and 8%, respectively, for the full year.

Amazon's year-over-year revenue and earnings rose by 20% and 14%, respectively, last year. In the first half of 2020, its revenue rose 34% as its earnings grew 24%, even as it racked up billions of dollars in COVID-19 expenses.

Increased online shopping throughout the pandemic boosted Amazon's North American and international revenue 36% and 28%, respectively, year over year. Its AWS revenue rose 31%, thanks to the elevated usage of cloud-based services throughout the crisis. Analysts expect that momentum to continue with 32% revenue growth and 38% earnings growth this year.

Which stock is more reasonably valued?

Walmart trades at 26 times forward earnings, which is much lower than Amazon's forward P/E of 58. Walmart also pays a forward yield of 1.5%, while Amazon doesn't pay a dividend.

Walmart might initially seem like the cheaper stock, but its multiple seems a bit frothy for a mature retailer with single-digit earnings growth. Amazon's P/E ratio is high, but it's arguably justified by its double-digit growth rates, its expanding margins, and the secular growth of its e-commerce and cloud businesses.

Walmart and Amazon are both still solid long-term investments. But I believe Amazon is cheaper relative to its growth, and its stock should outperform Walmart's for the foreseeable future.