As two of the most valuable companies in the world, you can't go wrong with adding shares of Alphabet (GOOG -2.81%) (GOOGL -2.76%) or Apple (AAPL -2.54%) to your portfolio. Both businesses have seen their stock prices rise over 100% in the last five years, despite the pandemic and a recent decline in consumer demand.

Although these companies have seen significant gains over the past five years, the tech sector has fallen out of favor in 2022, which has led Apple's and Alphabet's stocks to lose 17% and 29%, respectively, since January. With shares on sale, many investors are eyeing these two companies.

While Alphabet's and Apple's stocks are each likely to grow further over the next several years, one is undoubtedly the better choice. Let's assess.

Alphabet: An advertising titan

As Google's parent company, Alphabet is home to some of the world's most recognizable brands, including Android, Chrome, YouTube, Google Maps, and, of course, its Google search engine. The company's Google services segment comprises revenue from all of these platforms, mainly driven by ad revenue. As a result, Alphabet has held a majority market share in digital advertising since 2016, outshining companies such as Meta Platforms, Amazon, and Alibaba

Advertising made up about 90% of Alphabet's revenue in the second quarter of 2022, with 6.6% coming from its cloud business. Digital advertising has been a lucrative business for years, but with companies such as Netflix and Disney getting into the game with the introduction of streaming ad-supported tiers, demand is likely to continue for years to come. In fact, U.S. digital ad spending is expected to hit $239.89 billion in 2022 and rise 31% to $315.32 billion by 2025. 

Moreover, Alphabet has been making headway in the $203.5 billion cloud market, holding the third-largest market share, with 10% as of Q2 2022. The industry is currently dominated by Amazon Web Services, which has a 34% market share, but Alphabet has slowly expanded its slice each year, having just a 6% share in Q4 2019. Alphabet's Google Cloud revenue is relatively small, but it has been steadily growing each year. From 2018 to 2021, segment sales rose from $5.8 billion to $19.2 billion and totaled $12.1 billion in the first six months of 2022. 

Alphabet's share price may have fallen significantly over the last few months, but its financials tell a different story. The economy could be on the brink of a recession, but that doesn't stop Alphabet from being a great long-term buy, as its business has the strength to reclaim its losses. 

Apple: Home of the all-powerful iPhone

On Sept. 29, Bank of America analyst Wamsi Mohan revised his recommendation for Apple's stock from buy to neutral. Mohan cited "weaker consumer demand" for the downgrade, leading the company's share price to fall 5.1%. 

Apple has been seen as a relatively safe area of the slumping tech market, as its stock has sunk 17% year to date versus the Nasdaq-100 Technology Sector index's 29% nosedive in the same period. The MacBook manufacturer has managed to stave off the worst of the market's declines, but future earnings are questionable after the launch of its new lineup of iPhones on Sept. 7.

This year's iPhone 14 saw Apple widen the gap between its Pro and base models, leading to record sales of the Pro versions as consumers opted for their exclusive features. However, it has also led to reports that the base models have seen a steep decline in sales. They had been the best-selling part of the lineup in previous years. As a result, Mohan stated he doesn't believe the iPhone 14 Pro and Pro Max will sell enough to offset decreases in revenue if overall unit sales tumble.

For the last decade, iPhone sales have made up between 40% to 70% of Apple's revenue, hitting 49% in its most recent quarter of 2022. Analysts are right to be concerned about a potential dip in iPhone sales because its smartphone business is truly its bread and butter.

Should you buy Alphabet or Apple stock?

Apple is one of the most valuable companies in the world by market cap, with a clever business model that pulls consumers deeper and deeper into its ecosystem of products with just one purchase. Its share price has managed to fare better than many other tech stocks in 2022, but the iPhone 14 could spell trouble for the company in the coming year.

On the other hand, Alphabet's Google services and Cloud segment have produced promising growth and seem capable of pushing through market declines. There's a chance its ad revenue could fall if a recession hits, but its businesses are so varied that the company is still a solid long-term buy. 

Moreover, Alphabet's price-to-earnings ratio is currently 31% below what it was a year ago and sits at an all-time low. Meanwhile, Apple's is 10% lower than last year and double its all-time low in 2019, cementing Alphabet's stock as a better value and a better buy.