As investors get more defensive, they may look at stalwart stocks -- businesses that will be fine regardless of whether the U.S. plunges into a recession. Two companies that come to mind when discussing stalwart businesses are Costco Wholesale (COST -0.18%) and Home Depot (HD 2.51%).

Both have been around long enough to weather multiple recessions and economic downturns. But which one is better-positioned for the economic future that awaits us? Let's find out.

Home Depot is more prone to discretionary spending

Both businesses are consumer-facing retail chains. However, the mechanisms behind the businesses are vastly different.

Costco operates a members-only warehouse club, which offers its products in bulk at a discount. A Costco membership becomes invaluable as consumers look for ways to save money. Just by filling up a 15-gallon tank of gas every other week and saving $0.20 per gallon, Costco users will save $78 annually, more than a membership.

Throw in all of the other benefits (including the inflation-busting $1.50 hot dog), and it's easy to see why Costco will do fine regardless of what happens with the economy.

Home Depot is a bit more discretionary than Costco. Consumers must buy food and fill up their vehicles, but they can put off the deck remodel or kitchen renovation.

However, Home Depot will always have a constant flow of business because something in a house will inevitably break. Also, fewer home owners are looking to move to a different house because of sky-high mortgage rates, so if they do have cash lying around they may opt to improve their home instead of moving.

Both businesses will be able to weather the storm easily, but how are they doing right now?

Costco notched more stellar results recently

Home Depot reported its second-quarter results back in August, which were stellar. Sales grew 6.5% year-over-year to $43.8 billion, the best Q2 on record. However, this occurred through unfavorable circumstances.

In Q2, the average comparable ticket rose by 9%, but transactions declined by 3.1%. This means that inflation saved Home Depot's quarter, as fewer transactions mean less business.

Still, the company's earnings per share (EPS) rose 11.5% year over year, showing Home Depot is becoming more efficient. The company also reiterated its full-year guidance of 3% sales growth and mid-single-digit EPS growth, which is nothing spectacular.

In stark contrast to Home Depot's relatively small gain is Costco's market-beating growth. Costco recently wrapped up its fiscal year 2022 (ended Aug. 28) and reported Q4 results alongside it.

A lot has changed over the past year, so I'll focus on Q4 results only, as it gives investors a better picture of what to expect in the coming quarters. In Q4, Costco's U.S. sales rose 15.8% year over year (and 9.6% when rising gas prices are stripped out). Additionally, its EPS growth of 11.7% was practically in line with its sales growth of 13.7%. 

Costco also reports sales monthly, and September saw another strong U.S. month with 11.2% growth including gas sales (and 8% growth without). The company doesn't give guidance, but its business seems to be executing at a high level.

Which stock should you buy?

In reality, both companies are great, and you can't go wrong with either. However, the stocks are priced differently.

HD PE Ratio Chart

Data source: YCharts.

Based on their price-to-earnings (P/E) ratios, Home Depot's stock is the cheapest it has been in some time, while Costco's is still above its pre-COVID levels. With Costco valued at nearly double Home Depot's earnings, you own about as much of the business of Costco with one share as you would with two shares of Home Depot. This reality plays out in the dividend yields as well.

HD Dividend Yield Chart

Data source: YCharts.

While Costco's business may perform better (and can better resist an economic slowdown), the stock is highly valued and pays a relatively small dividend. On the other hand, you can buy Home Depot stock for a cheaper price and a much higher dividend yield.

Ultimately, it boils down to what you're looking for in a stock. Home Depot is likely a better buy if you're looking for solid dividend income. On the other hand, Costco may be a better pick if you're more of a growth investor. 

Still, Home Depot represents a greater value here because of its lowest sustained valuation in 10 years. It's not often you get to pick up a successful business like Home Depot for a cheap price, but it's staring investors right in the face today.

I don't think Costco is a bad buy, but with rising interest rates, investors' appetite for risk is falling, which could drag Costco's premium valuation with it. Sometimes, a business can thrive while its stock tumbles -- an action that wouldn't surprise me if it happened to Costco.

Time will tell which of these companies is a better buy, but I think both will outperform the market over the next five years.