It might surprise some investors that shares of Amazon.com (AMZN 3.43%) have only marginally outperformed Wal-Mart Stores (WMT -0.08%) stock over the past 12 months. Wal-Mart is using its massive scale as a brick-and-mortar retailer to push its way further into online shopping, snatching up smaller e-tailers and taking on Amazon.com.

Wal-Mart's online sales are growing faster than Amazon's now, and management expects e-commerce sales to climb another 40% next year. But Wal-Mart's total sales growth is still in the low single digits compared to Amazon's top-line growth around 30%.

After their respective run-ups in price, investors interested in the retail giants may have trouble deciding which stock makes a better buy. Let's break it down.

Walmart.com boxes coming down a conveyor belt.

Image source: Wal-Mart.

Competitive advantages

Wal-Mart boasts some significant competitive advantages over other retailers. Its massive footprint of over 11,000 stores and around 1.4 billion square feet means one of its stores is never too far away. With the majority of its sales coming from groceries, Wal-Mart is able to drive a ton of repeat customer traffic to its stores.

Wal-Mart has been able to leverage its footprint and grocery sales to grow online grocery sales. Online shoppers are able to order groceries online for pickup at over 1,000 locations in the U.S. Wal-Mart plans to expand to another 1,000 stores this year, covering practically every market it serves.

Wal-Mart also uses its stores to help meet fulfillment needs for online sales. It launched free two-day shipping on about 2 million items at the beginning of last year in order to compete with Amazon Prime. The number of eligible items continues to grow.

But Amazon may have an even bigger competitive advantage than Wal-Mart. Its Prime membership makes it a dominant force in online sales, with about half of online product searches beginning on Amazon (and the majority of them ending there). Prime makes customers loyal to Amazon, enabling the e-tailer to grow sales faster than the overall market and continue taking share.

Amazon benefits from a network effect where it attracts more shoppers to Prime, which attracts more third-party sellers to its Fulfillment by Amazon program, which further attracts more shoppers to Prime. There are now over 100 million Prime-eligible items for sale on Amazon.com.

Amazon also has a first-mover advantage in the growing smart speaker industry, as well as the more established e-book market. Its line of electronic devices offers an unparalleled onboarding tool for new customers and Prime members.

Amazon's competitive advantages seem to outweigh Wal-Mart's, but both are sufficiently safe from significant competitive threats.

Amazon.com boxes coming down a conveyor belt.

Image source: Amazon.

Valuation

It's important to note Wal-Mart stock and Amazon stock shouldn't be compared based on their valuations. Wal-Mart is a slow-growing retail juggernaut. Amazon, while also a retail juggernaut, is rapidly growing and has several avenues for further growth down the line including cloud computing, advertising, grocery delivery, and digital media.

As such, it's better to compare the two companies' valuations versus their historical valuations.

Valuation Metric

Wal-Mart

Wal-Mart 5-Year Average

Amazon

Amazon 5-Year Average

Price/Earnings

29.2

15.8

362.5

490.2

Enterprise value/Earnings before interest and taxes

17.8

10.9

180.6

184.4

Price/Sales

0.7

0.5

4.2

2.5

Price/Cash from operations

11.6

7.8

42.9

26.9

Data sources: Yahoo! Finance, YCharts, Morningstar.

As you can see, both Wal-Mart and Amazon shares are trading well above their historical valuations based on sales and cash flow. Amazon is trading slightly lower when you look at its earnings -- both net income and EBIT -- but considering Amazon's historic inconsistency in producing profits, that doesn't mean too much.

Wal-Mart's valuation looks quite a bit more stretched compared to Amazon's considering there aren't very many significant growth drivers for the company. It takes a lot of energy to move a mountain. Despite strong online sales growth, Wal-Mart's top line is only growing around 3% per year. The bottom line isn't growing much faster, with analysts forecasting EPS growth of around 7% per year over the next five years.

Both companies' stocks are priced relatively high right now, but if you're going to buy an overpriced stock, it's best to pick one with the greatest growth prospects. In this case, that's Amazon.