You might have to go back more than a decade, but for a time, HP (NYSE:HPQ) was the king not just in personal computing -- but computers in general. Before Macs re-emerged and mobile was the way new internet users joined the information age, HP was one of the biggest component makers of them all.

But that was then, and this is now. In place of hardware makers, those who offer software-as-a-service (SaaS) are the real kings of the tech space.

A smartphone with the images of apps superimposed above it.

Image source: Getty Images

By making a program that's downloadable on any device around the world, SaaS companies are able to enjoy enormous margins. Microsoft (NASDAQ:MSFT) is one such company, with its ubiquitous Office Suite and 365 offerings.

So does that mean Microsoft is a better buy at today's prices? Not necessarily. As you'll see below, there are lots of ways to gauge which is a better stock to buy. When taken together, one clearly rises to the top.

Sustainable competitive advantage

There's nothing more important for long-term investors to research than a company's sustainable competitive advantages -- otherwise referred to as its "moat." At its most basic level, a moat is what protects a company from the competition, keeps customers coming back for years, and produces market-thumping results.

Microsoft has a powerful advantage in high switching costs. It's namesake Office Suite -- which includes Word, Excel, and PowerPoint -- has been around for more than a decade and is easily the de facto system for use around the world. The company's newer branding of Office 365 is an extension of such high-switching-cost services. There's a powerful incentive to stay with what you -- and everyone around you -- knows.

Microsoft is able to take the cash from those lines of business and plow it into other pursuits as well -- like Azure, the company's efforts at cloud hosting.

After a number of spinoffs, HP's focus today is somewhat different from years past. It is squarely focused on computer hardware and printer sales. And despite what you may be reading in the headlines, the company is actually making market-share gains to once again make it the top dog in PC sales.

The real question is now whether having more market share of a potentially shrinking pie is worth it. While HP could end up with a true coup on its hands from a sandbox few are paying attention to, the power of Microsoft's moat is far ahead of HP's.

Winner = Microsoft 

Financial fortitude

For a long time, tech companies simply didn't offer dividends. That isn't the case anymore, with both HP and Microsoft as shining examples. Therefore, it'd make sense to want the companies to spend most of their cash on rewarding shareholders.

But that's not necessarily the best long-term way of approaching allocation. Every company, at one point or another, will experience difficult economic times. Those that have built up a sizable war chest -- and eschewed long-term debt -- usually become stronger as a result of such times: outspending rivals to drive them into bankruptcy, buying back shares on the cheap, or even making splashy acquisitions.

Remembering that Microsoft is valued at almost nine times the size of HP, here's how the two stack up.

Company

Cash

Debt

Net Income

Free Cash Flow

Microsoft

$139 billion

$76 billion

$21 billion

$31 billion

HP

$7 billion

$6.7 billion

$2.4 billion

$3.3 billion

Data source: SEC filings, Yahoo! Finance. Net income and free cash flow presented on trailing 12-month basis. Figures rounded to nearest billion.

Both of these companies have strong cash flows that should give investors comfort. But Microsoft has a much bigger war chest, especially relative to debt, than HP. That makes me think it has a better chance of actually benefiting from a market swoon than HP.

Winner = Microsoft

Valuation

And then we have the can of worms that is valuation. There's no one metric that can tell you just how expensive a stock is. Instead, I like to use a number of data points to get a more holistic picture.

Company

P/E

P/FCF

PEG Ratio

Dividend

FCF Payout

Microsoft

23

19

2.7

2.1%

38%

HP

12

10

5.2

2.7%

27%

Data source: SEC filings, Yahoo! Finance, E*Trade, Nasdaq.com. P/E represents non-GAAP earnings.

While some think HP is more expensive relative to its growth prospects (PEG Ratio), the company is far and away a better deal than Microsoft on all the other traditional metrics.

Not only does it sell for a bargain-basement 10 times free cash flow, but it has tons of room to grow its dividend moving forward.

Winner = HP 

My winner is...

So there you have it: While HP is definitely a cheaper stock on traditional metrics, Microsoft has both a stronger balance sheet and a wider moat -- making it the winner of this contest.

Teresa Kersten is an employee of LinkedIn and is a member of The Motley Fool's board of directors. LinkedIn is owned by Microsoft. Brian Stoffel has no position in any of the stocks mentioned. The Motley Fool has no position in any of the stocks mentioned. The Motley Fool has a disclosure policy.