Walmart (WMT -1.36%) and Costco Wholesale (COST -1.03%) are two of the biggest names in retail. They are massive businesses that can use their strong positions in the market to command low prices from vendors, allowing them to provide good value for their customers. And investors have recognized this, flocking to these shares as safe-haven investments amid economic uncertainty.
In the past 12 months, both stocks have risen by more than 25%, outperforming the S&P 500 and its 12% gains over the same time frame. But which retail stock is the better buy from here on out?

Image source: Getty Images.
Which company has better growth prospects?
For forward-looking investors, it's always important to consider the future, not simply rely on the past, when deciding on which stock to buy. This year, Walmart expects its sales to grow by around 3% to 4%. But it also said that it may have to raise prices, as soon as this month due to tariffs.
This is still a fairly short-term problem for the business. In the long run, the company has promising opportunities in expanding via online retail, it plans to open more stores in the U.S., and its acquisition of TV maker Vizio can enhance its growth opportunities in advertising.
Costco, meanwhile, has been expanding its global presence, opening multiple stores in China last year. And with just seven locations in the country, there's a huge opportunity to expand there, along with other markets.
The bulk of Costco's warehouses are in North America, and global expansion is a massive opportunity. And organically, the business is still doing well. The company reports earnings later this month, but its comparable-store sales for the 35-week period ended May 4 grew 5.9%. And its e-commerce business grew by 16.3% during that time frame.
Ultimately, I give the edge to Walmart when it comes to growth. Its business is a bit more varied than Costco's. And with Walmart focusing more on groceries and necessities, there's arguably more of a need to go to your local Walmart than there is to a Costco, where you may simply end up destroying your budget by spending much more than you planned; Walmart's growth may hold up better in a tougher economy than Costco's will.
Which stock is more expensive?
Both of these stocks have generated some strong gains over the past year, and inevitably, valuation will be a big question mark when deciding which of these stocks to buy. A good way to gauge their values is with respect to earnings. Neither one of them, however, looks terribly cheap right now.
WMT PE Ratio data by YCharts.
At a price-to-earnings multiple (P/E) of 40, Walmart is more attractively priced, but it's still trading well above the S&P 500 average P/E of 24.
Walmart is the stock I'd buy today
Both of these businesses are solid and continue to do well, making it a challenging decision to pick between them. But the better buy right now looks to be Walmart.
Although it's up 50% over the past 12 months, Walmart's P/E multiple is significantly lower than Costco's. And by focusing on essentials while also having strong growth opportunities ahead in multiple areas, it can make for the better buy in both the short and long terms.
Now can be a risky time to invest in the stock market, amid so much economic uncertainty. But with a trusted brand and strong financials, Walmart is the type of stock you can buy and forget about for a long while.