Image source: Getty Images.

These two companies rewrote the playbook in retail. When no one was focused on it, Whole Foods (WFM) championed healthy eating by educating its customers about the virtues of natural and organic goods. Costco (COST 1.00%) demonstrated that you can be a big-box retailer, take care of all your stakeholders (customers, shareholders, and employees), and still be successful.

Taking this differentiated approach led to massive gains for shareholders in both companies.

WFM Total Return Price Chart

WFM total return price data by YCharts.

But that's a backwards-looking approach, and the stock market is solely concerned with the future. So, between these companies, which is the better buy today? There's no surefire way to answer that question, but there are a number of different approaches we can take to the question that might give us a better understanding.

Financial fortitude

Cash really is king. While investors often like seeing excess cash either reinvested in the company or distributed to shareholders, companies that keep a hefty war chest on the balance sheet are often rewarded for their prudence.

That's because every company will face times of crisis. Whether macro or company-specific in nature, those with cash have options. Such companies can keep paying their dividend, buy back shares, outspend rivals into oblivion, or even make acquisitions. In fact, cash-rich companies usually emerge from recessions stronger than they were before.

The opposite is true for debt-heavy groups, as they are forced to narrowly focus on making ends meet and avoiding bankruptcy.

Here's how Whole Foods and Costco stack up in terms of financial fortitude.

Company

Cash

Debt

Net Income

Free Cash Flow

Whole Foods

$0.85 billion

$1.05 billion

$0.5 billion

$0.4 billion

Costco

$6.1 billion

$3.9 billion

$2.4 billion

$2.7 billion

Data source: Yahoo! Finance.

For a long time, Whole Foods refused to keep debt on the balance sheet. That changed a few years back, as management decided to be opportunistic with low interest rates and use the money to buy back shares that they considered cheap.

While that may end up being a savvy move, there's no doubt that Costco has the superior balance sheet. While it's important to put these numbers in perspective -- Costco is valued at over seven times the size of Whole Foods -- there's a huge benefit to having more cash on hand than debt. If the economy falters again, Costco shareholders can take solace in their superior balance sheet.

Winner = Costco

Sustainable competitive advantages

In my humble opinion, this is the most important variable of all. Often referred to as a "moat" by professional investors, a sustainable competitive advantage is what separates one company from the rest of the pack. Over the decades-long time horizon, companies with a solid moat -- that special sauce that gives them their identity -- are often the best investment.

For a long time, Whole Foods had the advantage of being the only major grocer toiling away in the natural/organic market. While others had a small portion of their stores devoted to the same fare, it was often more expensive.

The times, however, have changed -- and with it, Whole Foods' moat has started to disappear. Kroger, Wal-Mart, and (you guessed it) Costco have all become major purveyors of organic goods. With many more collective locations than Whole Foods -- and prices that can challenge Whole Foods and reinforce the "Whole Paycheck" moniker -- it has simply become more convenient for shoppers to get their organic food at the closest location, whatever that may be.

Costco, on the other hand, has a much stronger moat. The company makes virtually no money on the products it sells. Last fiscal year, it made $2.35 billion in net income. What's telling is that it brought in $2.65 billion in sales from membership dues alone. In other words, if we pull out membership dues, Costco is essentially a charity organization donating goods to its members.

Why is that so important? Because if any competitor wanted to challenge Costco, they would have to deal with Costco's enormous head start -- it has over 87 million card-carrying members -- and find a way to offer goods for less while still turning a profit. Costco's margins are so thin that that would be very difficult to do.

Winner = Costco

Valuation

Finally, we have valuation. This is part art and part science. Usually, I consult these variables to get a read on how expensive a stock is.

Company

P/E

P/FCF

PEG Ratio

Dividend

FCF Payout Ratio

Whole Foods

21

26

4.2

1.7%

44%

Costco

30

27

2.6

1.1%

35%

Data source: Yahoo! Finance, Nasdaq. P/E represents figures from non-GAAP earnings.

To be honest, I think both Costco's and Whole Foods' stocks are priced far too high. While they might look different on an earnings basis, they are essentially the same on a free cash flow basis. And while both offer sustainable dividends, they are also very small.

In the end, I choose to side with Costco. Its PEG ratio -- which takes a company's growth rate into consideration versus its absolute price tag -- is over 35% cheaper than Whole Foods'. Unless Whole Foods is able to turn some heads with its 365 small-store format, I simply don't see the stock being worth the multiple it fetches today.

Winner = Costco.

Final Call = Costco

So there you have it. Costco soundly defeats Whole Foods on all three metrics. Does that mean that it's guaranteed to outperform Whole Foods? Certainly not. In fact, on my CAPS profile, I've given both an "underperform" rating, though my reasoning is differentiated. While I think Whole Foods' moat isn't strong enough to last, I believe that Costco's stock is simply too expensive. Were it to drop, I would definitely consider changing my stance.