Image source: Getty Images.

This is a classic battle of a disruptor getting disrupted. Back when Wal-Mart (WMT -2.34%) was founded in 1962, there were no giants supplying affordable goods in bulk to rural communities across America. That was the opportunity that Sam Walton seized.

But over time, the disruptor became the stalwart. People started to complain about how the company treated both its employees and its suppliers. And then came founder Jim Senegal and Costco (COST 0.97%), which -- while much smaller -- is using a membership-based program to turn Wal-Mart on its head, providing industry-leading benefits to employees and satisfying customers at the same time.

Of course, now both are being challenged by e-commerce behemoth Amazon.com. But the question for today's article is both simple and impossible to definitively answer: Between Wal-Mart and Costco, which is the better stock to buy?

Here are three lenses through which we can view the question.

Financial fortitude

This may sound boring, but how much cash a company has in the bank -- and how much it owes to debtors -- can be a huge deal if/when macro or company-specific troubles arise. Think about it: In a downturn, companies that have cash have options. They can outspend rivals, acquire rivals, buy back their stock, or continue paying a dividend without batting an eye.

Companies with lots of debt are in the opposite boat: forced to narrow their focus just to make ends meet -- while losing sight of the grander purpose that they believe they can accomplish.

Here's how Costco and Wal-Mart stack up in terms of financial fortitude:

Company

Cash

Debt

Net Income

Free Cash Flow

Costco

$4.7 billion

$5.5 billion

$2.4 billion

$643 million

Wal-Mart

$7.7 billion

$48.1 billion

$14.7 billion

$21.2 billion

Data source: Yahoo! Finance.

To be honest with you, neither of these companies is particularly impressive. On the one hand, Wal-Mart has a boatload of debt. That's not too big of a deal given the prodigious amounts of free cash flow (FCF) that it produces, but it's still a higher number than I'm comfortable with.

On the other hand, Costco's FCF leaves a lot to be desired. That's mostly because the company uses its cash generated from operations to help build new stores -- 31 of which are expected to be opened during the current fiscal year. I'm glad the company doesn't have to use debt to do this, but it means that it has been paying out more in dividends ($746 million) than it has from FCF. That's not a sustainable strategy.

In the end, I'm calling this a tie -- with a thumbs-down for both companies.

Winner: Tie

Sustainable competitive advantage

In investing circles, a sustainable competitive advantage is often referred to as a moat. In its most basic form, a company's moat is what makes it special, what separates it from the rest of the pack, and what will help it continue to be the provider of choice for (in this case) consumer goods shoppers.

Wal-Mart's moat comes primarily from the size of its network. With over 11,500 stores in 28 countries operating under an amazing 63 different banners, Wal-Mart is one of the most ubiquitous shopping destinations worldwide. This type of scale allows the company to bargain hard for low prices for customers, which is usually an enticing way to keep them coming back.

Costco's moat, on the other hand, is its membership-based business model. The prices for bulk goods at Costco are so low that membership fees are the only way that the company actually turns a profit. After all other expenses are taken into consideration, Costco would actually run at a loss without these fees ! Members know they can't get these deals anywhere else, and there really isn't a serious threat from any other nationwide membership warehouse either.

At the end of the day, I'd say both of these companies have medium-level moats.

Winner: Tie

Valuation

Finally, we have the question of how expensive each stock is. There's no "perfect" way to measure this, so I think it's worth exploring a number of data points. Here are four of my favorites.

Company

P/E

P/FCF

P/S

PEG Ratio

Costco

28

103

0.6

2.5

Wal-Mart

16

10

0.5

5.0

Data source: Yahoo! Finance, E*Trade, YCharts. P/E figures reflect non-GAAP EPS.

While both of these companies sport very high price-to-earnings-growth (PEG) ratios, there's a clear winner in my mind: Wal-Mart. While the company's days of heady growth are no doubt in the past, it produces a ton of cash flow, and trades for just 10 FCF. Because Costco is busy building out its network, it trades for 10 times that valuation.

Winner: Wal-Mart

Final call: Wal-Mart

There you have it. While I personally prefer Costco as a company to Wal-Mart, I think that Wal-Mart's stock is a better choice right now. More than anything else, I think Costco is just too expensive when all is said and done.