Last year was a fantastic one for the market with the S&P 500 jumping 24% after dropping by double digits in 2022. A lot of businesses benefited from the ongoing rally.

Look at warehouse club operator Costco Wholesale (COST 1.01%). Its shares surged 45% in 2023, outpacing the broader index. But then there's Home Depot (HD 0.94%), whose shares meaningfully underperformed, up just 10% last year.

There are valid arguments to be made for the investment merits of both of these top retail stocks, but let's see perhaps which one comes out on top.

The case for Home Depot

Home Depot is the leader in the home improvement industry, with its trailing-12-month revenue of $154 billion, which represents 16% of the market. That's certainly sizable, but it also shows the potential market share this business can take.

The company is hitting a bit of a rough patch and expects sales to decline between 3% and 4% in the current fiscal year. But management is optimistic about the industry, with an aging housing stock, the popularity of remote work, and a shortage of housing inventory in the U.S. All this supports long-term growth for Home Depot.

This business serves both do-it-yourself and professional customers, with each group representing about half of overall sales. Having such a sizable share coming from contractors, plumbers, and electricians, for example, has benefited Home Depot financially. It has historically produced a better operating margin and return on invested capital than its smaller rival Lowe's Companies, which only generates 25% of revenue from pros.

Investors will also find Home Depot's capital allocation policy to be very favorable. The business has paid a steadily rising dividend since 1987. The current yield of 2.4% provides a decent source of passive income.

And because the retailer produces so much free cash flow, management also engages in share buybacks, which increase the ownership stake of remaining shareholders.

The case for Costco

Looking at big-box retailer Costco's historical financials, the first thing you'll realize is how strong its performance was during and after the height of the pandemic. Revenue was up by double digits in fiscal 2021 and 2022.

And the momentum has continued. During a time when inflationary pressures have been a headwind, the business reported net sales growth of 6.7% in fiscal 2023 (ended Sept. 3).

Even if a severe recession were to cripple the economy, I suspect that Costco would be just fine. You can't say this about most other companies.

A key facet of Costco's business model is its memberships. Customers must pay annual fees for the right to shop at one of the company's warehouses, providing a stable source of revenue. This differentiates Costco from a typical retailer like Home Depot.

The membership model also can help drive incredible customer loyalty as consumers are incentivized to shop at a Costco location versus a competitor simply because they are members. In the first quarter of fiscal 2024, the membership renewal rate was 92.8% in the U.S. and Canada, indicating customer stickiness.

Costco is the world's third-biggest retailer, so you might assume that it doesn't have much growth potential left. This is a flawed assumption: For the current fiscal year, management plans to open 31 net new warehouses, up from 23 openings last year. China will be a huge growth source, as there are only six locations in the country today.

Is valuation your top concern?

Both Home Depot and Costco have attractive investment merits. The answer to which stock is the better one depends on how much you prioritize valuation.

Home Depot's current price-to-earnings ratio of 22.7 is far lower than Costco's 47.4. If your primary concern is to buy cheap stocks, then Home Depot is the clear winner here. But if you care about owning the highest-quality businesses, no matter what the price, then Costco is the no-brainer buy.