Even though indexes have rallied this year, many top companies have missed out on the gains. Certain consumer-related stocks have suffered as investors shy away from those that depend on spending. Rising inflation has weighed on buying power, leaving shoppers with less money in their wallets.

But now, while these players' shares are in the doldrums, it is actually the perfect moment to invest. In many cases, their long-term outlooks remain bright -- and today, you can buy these exciting stories for a bargain. Tractor Supply Co. (TSCO 3.26%) and Home Depot (HD 0.94%) are perfect examples, as shares of these top companies have declined since the start of the year. But if you could pick up only one right now, which would make the better buy? Let's find out.

Why you should buy Tractor Supply

Tractor Supply has built a solid earnings track record serving recreational farmers, ranchers, and even homeowners who like feeling close to the land. The company sells everything from power tools to riding mowers and pet supplies in more than 2,000 stores in 49 states.

The earlier days of the pandemic offered Tractor Supply an extra lift as people opted to stay home more and tend to their properties -- and, in some cases, even move to rural areas. The company saw its annual revenue and net income double from pre-pandemic days to last year.

TSCO Revenue (Annual) Chart

TSCO Revenue (Annual) data by YCharts.

As mentioned, the current economic environment has held earnings back in recent months -- and Tractor Supply noted the slowdown in spending during its second-quarter report. But even in this environment, the company still managed to increase sales and earnings per share.

The company also has a plan to make good use of its money and boost growth: Tractor Supply aims to sell and then lease back the 117 stores it owns -- then reinvest proceeds into opening new stores. The goal is to increase its store count to 3,000.

This year may represent a bit of a transition. The new store growth plan means Tractor Supply's capital expenditures may come in at about $800 million this year, higher than an earlier forecast of $700 million. And consumer spending may take a bit of time to recover. But Tractor Supply's efforts today could launch a new phase of growth for earnings and the stock over the next few years.

Why you should buy Home Depot

Home Depot's earnings were going strong all the way through last year. However -- like Tractor Supply -- the world's biggest home improvement retailer has seen a slowdown. In fact, Home Depot reported declines in sales and net income in the first two quarters of this year.

It's important to put this into perspective, though. The company predicted 2023 would be "a year of moderation after the explosive growth we had the prior few years." The company delivered $40 billion of sales growth in just two years -- 2020 through 2021 -- and then continued to increase sales and profits last year.

Another positive point is that today's troubles are temporary. The consumer, hurt by the economic environment, is putting off spending on big-ticket discretionary items. In some cases, that consumer is favoring spending on services, such as travel, for example. These trends will eventually come to an end.

Meanwhile, Home Depot's professional customer backlogs may be lower than a year ago -- but they're still high in relation to historical averages. This is important because it shows us that projects are in the pipeline, which should lead to sales for Home Depot in the coming quarters.

Home Depot has also shown other bright spots in the most recent quarter, with strength in certain product categories, like building materials and plumbing -- and the company continues to win in efficiency, with almost half of all online orders fulfilled through its stores.

Which stock should you buy right now?

Let's look at the valuations of both players. Today, Tractor Supply and Home Depot are trading at about the same level in relation to forward earnings estimates. In the past, Tractor Supply has generally trended higher by that measure.

HD PE Ratio (Forward) Chart

HD PE Ratio (Forward) data by YCharts. PE Ratio = price-to-earnings ratio.

Meanwhile, Tractor Supply has maintained earnings growth despite today's difficult environment, and the company's real estate plan could offer a boost in the coming years.

Home Depot's future also looks bright. Any sign of recovery in upcoming earnings reports could lift the shares.

But if I could buy just one of these top retail stocks today, I would go for Tractor Supply. Considering the company's current performance and long-term outlook, the stock looks particularly cheap -- and I wouldn't want to miss out on the deal.