Shoppers love Amazon (AMZN -2.56%) and Home Depot (HD 0.74%). But investors haven't been as enthusiastic about the companies in recent times. Shares of both have dropped in the double digits since the start of the year. And Amazon and Home Depot continue to face the challenges of rising inflation and a tough economic environment.

Over time, though, these two retail leaders have delivered gains in revenue, profit, and share performance. They also have a history of increasing return on invested capital and free cash flow. They've shown us they have what it takes to make a great long-term addition to your portfolio. And I'm confident about both stocks over time. But which is the better buy right now if you had to choose just one? Let's find out.

The case for Amazon

We'll talk about the negative points first. Higher inflation has weighed heavily on Amazon's e-commerce business. For example, the cost of shipping international containers has doubled from pre-pandemic days. Amazon also found itself with too much capacity after ramping up its fulfillment network during the early days of the health crisis.

As a result, the company has reported declines in operating cash flow and operating income over the past few quarters.

But here's the bright side of the picture. Amazon's cloud computing business continues to grow sales and operating income in the double digits -- and into the billions of dollars -- each quarter. This is significant because Amazon Web Services (AWS) generally is a key profit driver for the company. It made up more than 70% of total operating income last year. And AWS is the industry leader.

As for the e-commerce business, Amazon said it's made progress in controlling costs and improving its use of the expanded fulfillment network. Forecasts call for global retail e-commerce to grow in the double digits in the coming years, so Amazon's growth in this business is far from over.

The case for Home Depot

The pandemic resulted in people spending more time at home. And that led to high demand in home improvement projects. This hasn't waned. Strength continues in both the do-it-yourself market and the professional market. And that helped Home Depot to report its highest level of quarterly sales and profit ever in the second quarter.

Of course, Home Depot still faces the tricky job of managing today's economic situation. The company has invested in higher stock levels to combat supply chain disruptions. Home Depot says it wants to have products available for customers when they need them. The company also is putting money into new supply chain facilities. Overall, Home Depot invested $750 million in its business in the quarter.

It's not yet clear whether the economy will hurt demand in the coming months. But trends seen so far are reason to be optimistic about what matters the most: the long term.

"The long-term underpinnings of demand for home improvement remains strong," Chief Operating Officer Ted Decker said during the earnings call.

One clue: Professional customers have a solid backlog of projects. To ensure future success, Home Depot is improving its digital platforms and ramping up its services to professionals. So, the long-term looks bright for this market leader.

Amazon or Home Depot?

Over time, Amazon and Home Depot both have great prospects, as mentioned above. But Amazon has a longer road ahead when it comes to recovery. Key metrics of free cash flow and return on invested capital have declined at both companies this year. But Home Depot's measures seem to be stabilizing.

HD Return on Invested Capital Chart

HD Return on Invested Capital data by YCharts

Home Depot also remains highly profitable, while Amazon has posted net losses in the past two quarters.

At the same time, Amazon and Home Depot have seen their share prices and valuations fall.

HD PS Ratio Chart

HD PS Ratio data by YCharts

Both trade lower in relation to sales compared with earlier this year. But Home Depot trades even lower by this measure than Amazon, even as quarterly revenue reached historic highs.

At these levels, Home Depot looks particularly appealing, especially considering the company's recent earnings growth and demand for its products. And that's why, right now, Home Depot is the better buy.