In the past three years, shares of Apple (AAPL 0.51%) and Roku (ROKU 2.94%) are up 170% and 800%, respectively. In both cases, those gains crush the 63% total return of the S&P 500, though Roku was clearly the better buy in May 2018.

Unfortunately, we can't go back in time -- at least I can't. And a lot can change in three years. So let's take a closer look at these tech stocks today, so we can decide if Roku is still the better investment.

Apple

Since releasing the first iPhone in 2007, Apple has masterminded the creation of an incredibly profitable ecosystem. Unlike Android, the iOS operating system is closed-source; that means no original equipment manufacturers can bundle iOS with cheaper hardware to create an "Apple-ish" product.

Two people using their iMac computers.

Image source: Apple.

If you want the Apple experience, you have to buy Apple hardware. That allows the Cupertino company to charge a premium for its devices. For instance, the average Android smartphone sells for $261 in 2021, according to the International Data Corp. But the average iPhone price hit $873 last quarter.

Of course, this approach has allowed Android devices to capture more market share. But Apple's App Store still rakes in more cash than Google Play, the most popular Android app store. How is that possible? Simple. Developers prefer Apple.

A flywheel effect keeps this advantage in motion. A limited number of products support iOS, while thousands of different devices run Android's operating system. That makes it easier for developers to optimize the experience for Apple users, and a good user experience drives retention.

Additionally, App Store sales hit $72 billion last year, while Google Play sales came in at $39 billion -- in other words, Apple consumers spent more money, meaning iOS developers made more money. From a financial perspective, the better choice is clear.

In a nutshell, Apple's tightly controlled ecosystem -- hardware, software, and third-party apps -- gives the company an advantage. That has powered solid financial results over the long term.

Metric

2017

Q2 2021 (TTM)

CAGR

Revenue

$229.2 billion

$325.4 billion

11%

Free cash flow

$51.8 billion

$90.4 billion

17%

Data source: Apple SEC filings. Note: Q2 2021 ended March 27, 2021. TTM = trailing 12 months. CAGR = compound annual growth rate.

Looking ahead, Apple has a chance to take smartphone market share from rival Samsung this year. Wedbush analyst Dan Ives forecasts record-breaking iPhone sales of 240 million to 250 million units. Meanwhile, Samsung has warned investors that headwinds created by the semiconductor shortage will likely cause mobile profits to drop in the near term.

As a final thought, Apple is Warren Buffett's largest holding. That shouldn't make or break any investment thesis, but when the Oracle of Omaha has $108 billion invested in a single company, it's worth paying attention.

Roku

When Roku was founded in 2002, it gained popularity as a manufacturer of connected TV (CTV) devices. But in recent years, its platform services have become the growth driver. In fact, 81% of Roku's revenue came from its platform business last year. This includes its cut of transaction fees (i.e., users can pay for subscription services through the platform), as well as digital ad sales.

Group of young adults watching streaming content.

Image source: Getty Images.

Roku's acquisition of Dataxu in 2019 was a key factor in driving this transformation. Dataxu's ad tech platform -- rebranded as Roku OneView -- allows marketers to programmatically (i.e., using software) purchase ad space and launch data-driven campaigns across digital channels. Notably, this is not limited to streaming TV, but also includes mobile, desktop, and linear TV. As a result, Roku believes its platform can reach four out of five homes in the U.S.

More recently, Roku acquired Nielsen's Advanced Video Advertising business, including its dynamic ad insertion technologies. Now, marketers using the OneView platform can replace traditional ads on linear TV channels with targeted ads in real time.

That's only half of the picture, though. The other piece of the puzzle is Roku's user base. According to eMarketer, Roku is the most popular CTV platform in the U.S., with over 100 million users. By comparison, Amazon Fire TV ranks second with 73 million users. In general, more users means more marketing dollars, which gives Roku an edge.

That advantage has translated into rapid growth on both the top and bottom lines.

Metric

2017

Q1 2021

CAGR

Revenue

$512.8 million

$2.0 billion

53%

Free cash flow

$28.1 million

$157.3 million

70%

Data source: Roku SEC filings. TTM = trailing 12 months. CAGR = compound annual growth rate.

Looking ahead, more consumers are expected to cut the cord in the coming years, which should bring more marketing dollars to CTV. As that trend plays out, Roku's OneView platform and expansive user base should be powerful growth drivers, helping the company grow its share of the digital ad market.

The verdict

Apple currently trades at seven times sales, while Roku sits at 23 times sales. That makes Apple the cheaper stock. However, Roku is also growing much more quickly, so its premium valuation should come as no surprise.

Additionally, Roku has a market cap of $46 billion, meaning its roughly 45 times smaller than Apple. I think that leaves more upside for long-term investors. That's why Roku is the better buy.