Investors have vastly different ideas about Costco Wholesale (COST -0.72%) and Amazon (AMZN 0.77%) stocks right now. The e-commerce giant's shares are beating the market by a wide margin through mid-July, while the warehouse retailer is barely matching the 17% gain in the S&P 500.

That gap can be partly explained by shifting expectations around short-term growth trends. Costco is going through a slowdown on this score as consumers tilt spending away from many of the consumer discretionary purchases they favored over the last few years. Amazon, meanwhile, is targeting faster earnings growth ahead thanks to a slimmer cost profile and the expansion of niches like cloud services.

With that big picture in mind, let's take a closer look at these two businesses to see which could be the better fit in your portfolio.

The latest trends

Amazon's growth looks more impressive so far in 2023. Sure, revenue rose by just 9% in the most recent quarter. But that result was mainly due to flat product sales compared to soaring gains a year ago. The company's services segment, anchored by the AWS platform, is enjoying fantastic growth. Sales improved to $70 billion in Q1 from $60 billion a year ago. "There's a lot to like about how our teams are delivering for customers," CEO Andy Jassy said in a recent press release.

Costco, in contrast, has seen comparable-store sales gains slow to just 3% in June from over 6% a few months ago. Customer traffic remains solid at the warehouse retailer, but spending levels are being pressured by a shift away from the e-commerce channel that's tilted toward big-ticket home furnishing and consumer electronics purchases. Give the growth edge to Amazon, then.

The profitability winner

Amazon traditionally is more profitable, but Costco is winning in this area today. Operating profit margin has held steady at over 3% of sales in recent quarters, which is a testament to its membership-driven earnings. Over 91% of subscribers choose to renew their subscriptions each year, a record for the business. That success allows Costco to generate consistently positive earnings even when sales trends are slowing as they are today.

COST Operating Margin (TTM) Chart

COST Operating Margin (TTM) data by YCharts

Amazon, on the other hand, isn't as consistent with its earnings growth. The company's management team prioritizes cash flow over short-term profits, after all. If you're looking for stability in earnings, then Costco is one of the best stocks around.

Price and value

Costco shares have become cheaper lately, mainly thanks to those modest expectations around growth. You can own the stock for about 1 times annual sales, down from the pandemic high of around 1.25. Amazon's stock valuation is down as well, but it has risen a lot in 2023, from 1.7 times sales in January to 2.6 times sales right now.

If growth is your focus, and you don't mind volatile earnings results, then Amazon shares will be the better fit for your portfolio. Costco, meanwhile, will appeal to investors who value stable sales and profit growth. Neither stock looks especially expensive right now, though, meaning you are likely to see solid returns from putting either -- or both -- in your portfolio.