McDonald's (MCD 0.38%) and PepsiCo (PEP 1.65%) are two of the most iconic brands in the world. McDonald's operates and franchises over 36,000 restaurants in more than 100 countries, while PepsiCo's beverages and packaged foods are consumed in over 200 countries and territories.

McDonald's and PepsiCo's stocks jumped over 500% and 200%, respectively, over the past 20 years -- easily outpacing the S&P 500's 110% gain. But past performance never guarantees future gains, so let's take a fresh look at both stocks to see which is the better overall buy.

A glass of cola being poured in front of a burger and fries.

Image source: Getty Images.

Shared challenges, different solutions

McDonald's and PepsiCo operate different kinds of businesses, but both companies have struggled with a shared problem: More consumers are avoiding traditional fast food chains and sodas in favor of healthier alternatives.

McDonald's faces competition from "fast casual" challengers like Panera and Chipotle, while PepsiCo is struggling with declining soda consumption rates. PepsiCo's Frito Lay and Quaker units also face fierce competition from other packaged food giants, smaller brands, and private label brands.

To address those problems, McDonald's added healthier and regional menu items, replaced its frozen beef with fresh beef, and launched an all-day breakfast. It also renovated its stores, installed digital kiosks which streamlined in-store orders, and expanded is online ordering and delivery options with third-party partners.

PepsiCo expanded its beverage portfolio by developing and acquiring new brands of bottled water, sparkling water, tea, juice, and even hybrid cola-coffee drinks. It also launched healthier versions of its Frito Lay snacks and refreshed its aging Quaker brand for health-conscious consumers.

How fast are McDonald's and PepsiCo growing?

McDonald's and PepsiCo both have a lot of moving parts, but their strengths are largely offsetting their weaknesses.

McDonald's global comparable store sales grew 5.9% in 2019, marking its strongest comps growth in more than a decade. But in the first quarter, its global comps dipped 3.4% as the COVID-19 crisis shut down its restaurants. McDonald's withdrew its full-year guidance, but analysts expect its revenue and earnings to tumble 13% and 21%, respectively, this year.

A McDonald's location in an airport.

Image source: Getty Images.

PepsiCo's organic sales rose 4.5% in 2019, as it leveraged price hikes to offset softer shipments of its drinks and packaged foods. In the first half of 2020, its organic sales grew another 3.3%, as a spike in COVID-19-inspired shopping in the first quarter offset a slowdown in the second quarter -- which was largely attributed to the shutdowns of convenience stores, gas stations, and other smaller brick-and-mortar retailers. PepsiCo also withdrew its full-year guidance, but analysts expect its reported revenue to stay flat as its earnings dip 3%.

McDonald's and PepsiCo are both expected to generate stronger sales and earnings growth next year. However, investors should be wary of those long-term predictions, which could be easily rendered obsolete by a second wave of COVID-19 infections, the escalating U.S.-China trade war, and other unpredictable macro headwinds.

Dividends and valuations

McDonald's and PepsiCo are both Dividend Aristocrats of the S&P 500, having raised their dividends annually for at least 25 straight years.

McDonald's pays a forward dividend yield of 2.7%, while PepsiCo pays a forward yield of 3%. McDonald's suspended its buybacks earlier this year to conserve cash and protect its dividend, but PepsiCo plans to keep buying back additional shares throughout the year. 

McDonald's trades at 32 times forward earnings, while PepsiCo has a lower forward P/E of 24. Both valuations are high relative to their earnings growth, but investors are likely willing to pay a premium for their stability, dividends, and resilience during market downturns in this wobbly market.

The winner: PepsiCo

McDonald's and PepsiCo are both safe long-term investments. But if I had to choose one over the other, I'd buy PepsiCo because it's better insulated from the COVID-19 crisis, trades at a lower multiple, pays a higher dividend, and generates enough free cash flow to comfortably cover its buybacks.