The retailing industry's growth struggles have kept a lid on investor returns for most stocks in this sector. But Costco Wholesale (COST -0.44%) and Walmart (WMT -0.80%) are bucking that negative trend with help from their scale, market share growth, and efficient business models.

Both companies recently updated investors on their operating trends into early 2023, so let's see which one is the better buy right now.

Winning through the holidays

Both companies showed surprising strength through the holiday season in late 2022, meaning investors' worries were overblown. Walmart said in its fourth-quarter report that comparable store sales were up 8% in the core U.S. market through late January. Costco's seeing similar strength, with comps rising 7.1% into early 2023.

One key trend to watch is customer traffic, which has slowed but is still rising for these companies. More consumer discretionary retailers like Home Depot have noted falling traffic levels in recent months. In contrast, Costco said in January that traffic rose 2% in the U.S. last quarter. Walmart posted a 2% uptick here in Q4 as well, implying solid trends for both businesses.

Margin pressures

Walmart is under more profitability pressure than its smaller rival, though. The company had to lower its earnings forecast last year, and in Q4 it reported modest declines in both gross and operating profit margins.

Chart showing declines in operating margin for both Walmart and Costco in 2022, with Walmart's much steeper.

WMT Operating Margin (TTM) data by YCharts

Of course, some of that difference can be explained by the fact that Costco's profitability is already so low. The warehouse giant generates most of its earnings from subscription fees rather than product markups, and it prides itself on being a "price leader." That approach tends to keep a lid on margins while boosting long-term metrics like customer loyalty. Costco is in a class of its own here, too, with member renewal rates at over 92% in the U.S. recently.

Cash and value

Walmart edges past its rival in the cash return department. It has a longer track record of consistently boosting its dividend payout, and management prioritizes those returns.

That focus is clear from the fact that Walmart's stock yields nearly twice as much as Costco's. The warehouse giant trails here in part because executives prefer to use one-time special payouts rather than to commit to a steadily rising dividend that returns most annual profits to shareholders each year.

Finally, Costco shares are priced at a premium of nearly 1 times annual sales compared to Walmart's 0.6. Sure, the warehouse giant deserves some of that premium, mainly because its membership model makes it less exposed to big declines in sales or profitability during times of economic slowdowns. Costco's record renewal rate also implies that it will have no trouble passing along its next fee hike, which tends to immediately boost earnings. Look for that increase to potentially arrive as early as mid-2023.

Those factors make Costco the more attractive stock for most investors today. Walmart will appeal to value-focused investors who are seeking dividend income. But because of its recession resistance and its excellent growth profile, Costco seems worth the higher relative price.