It wasn't that long ago that retail was won and lost based on your relationship with Wal-Mart (WMT 1.31%). The company's size and scale meant that it had unprecedented pricing power that could squeeze local mom-and-pop stores and offer customers the best deals possible.

While much of that advantage remains today, Wal-Mart has been usurped by the emergence of e-commerce. No company embodies this trend more than Amazon.com (AMZN -1.44%), and the company's dominance over Wal-Mart on this front has been reflected in the performance of its stock: since the darkest days of the Great Recession, Amazon stock has returned 2,250% for shareholders -- or over 13 times Wal-Mart's return.

Paper boxes in a shopping cart on a laptop keyboard.

Image source: Getty Images

But which stock is the better bet moving forward? After years of fumbling its e-commerce game, Wal-Mart's acquisition of Jet.com has proven to be the catalyst the company needed. Is that enough to push it above Amazon's expensive stock?

While we can never know with 100% certainty which stock will outperform over the long-run, we can get a better idea of what we're paying for by evaluating them through three different lenses.

Sustainable competitive advantage

If you're a long-term, buy-to-hold investor, there's nothing more important to investigate than a company's sustainable competitive advantages -- sometimes referred to as a moat. In the simplest sense, a moat is what keeps customers coming back to you rather than your rivals for years, while holding the competition at bay for decades.

Amazon and Wal-Mart both benefit from strong brand names. According to Forbes, Amazon comes in seventh globally, with a brand worth over $54 billion. Wal-Mart comes in 24th, with a brand value of $24 billion.

That's not the only facet where Amazon has the upper hand. Wal-Mart benefits from low-cost production thanks to its scale, but Amazon has upended that advantage, by not only offering products at low cost but guaranteeing delivery in two days or less for a very small cost -- something no one else in the world could do -- thanks to its network of fulfillment centers.

Amazon also benefits from powerful network effects: As more customers flock to the site, third-party vendors are incentivized to list their wares on the site and use Fulfillment by Amazon. As more third-party merchants list their goods, more users flock to the site, creating a virtuous cycle that helps give Amazon a wider moat than Wal-Mart.

Winner = Amazon

Financial fortitude

Next, we have financial fortitude. Usually, investors in Amazon want to see extra cash get plowed back into future growth initiatives. Wal-Mart attracts a different kind of investor: one focused on cash being returned to shareholders via dividends and share buybacks.

But there's something to be said for keeping a boring pile of cash on hand. That's because every company, at one point or another, is going to face difficult economic times. When those times hit, cash-rich companies can actually get stronger via share buybacks, acquisitions of smaller industry players, or by simply bleeding out the competition by undercutting them on price.

Keeping in mind that Amazon has almost twice the market capitalization of Wal-Mart, here's how the two stack up.

Company

Cash

Debt

Free Cash Flow

Amazon

$31 billion

$58 billion

$6.5 billion

Wal-Mart

$7 billion

$41 billion

$18.7 billion

Data source: Yahoo! Finance. Cash represents cash, short- and long-term investments. Free cash flow presented on trailing twelve month basis.

Until recently, Amazon had a much less-levered balance sheet. But the acquisition of Whole Foods changed that, and for the first time in a while, the company sports more debt than cash. That being said, its leverage is nothing compared to what Wal-Mart has taken on. 

But if we look at the incredible free cash flow that Wal-Mart's established network of stores produce, we see that these two are on fairly even footing, with Wal-Mart having superior cash flows and Amazon having a healthier balance sheet.

Winner = Tie

Valuation

Finally we have valuation. There's no single metric that can tell us which stock is a better buy. Instead, it helps to consult a number of different figures to build out a more holistic picture.

Company

P/E

P/FCF

PEG Ratio

Dividend

FCF Payout

Amazon

320

108

6.3

N/A

N/A

Wal-Mart

24

16

3.2

1.9%

37%

Data source: Yahoo! Finance, E*Trade, Nasdaq.com.

Even though Amazon recently posted its highest net income ever, the company is still ridiculously expensive by traditional metrics. Wal-Mart's price tag of 16 times trailing free cash flow is a very fair price for a company that recently found its e-commerce groove, and makes it a better deal on valuation at today's prices.

Winner = Wal-Mart

The winner is...

So there you have it: we have a tie. When this happens, I always use the stronger moat as the tie-breaker. In this case, that means Amazon. This isn't surprising, as the strength of the company's moat is why I have allowed it to continue growing to account for 20% of my real-life holdings.

At the same time, I'm very impressed by what Wal-Mart has been able to accomplish over the last year, and at these prices I'm willing to give the company an "outperform" rating on my CAPS profile as well.