Holding onto a stock for decades, through all of its ups and downs, is hard. The urge to sell, either because the stock declined or because it rose too quickly, is powerful. Those able to stick it out, assuming they chose their stock wisely, benefit from the overwhelming power of compounding. Patience is what separates success and failure when it comes to long-term investing.

While hindsight is 20-20, it can still be useful to see which stocks produced an inordinate amount of wealth in the past. There's no guarantee this performance will continue, but it does say something about the quality of the company. Here's how NVIDIA (NASDAQ:NVDA) and Starbucks (NASDAQ:SBUX) turned a $10,000 investment into more than $1 million.

Stacks of coins, each higher than the next, representing growth.

Image source: Getty Images.

From graphics to everything else

NVIDIA, known best for its graphics processing units used for PC gaming, was founded in 1993 and went public in 1999. The company's market capitalization following its first day of trading was about $626 million. The stock was pricey at the time, trading for around 12 times sales, but NVIDIA would go on to dominate the market for PC GPUs and eventually diversify well beyond the PC. The company is valued at nearly $60 billion today.

NVDA Total Return Price Chart

NVDA Total Return Price data by YCharts

Including dividends, NVIDIA stock has returned about 10,500% since going public, turning $10,000 into a little over $1 million. There were plenty of ups and downs as the company battled ATI and later Advanced Micro Devices, which bought out NVIDIA's rival in 2006, for graphics supremacy. The stock surged only to collapse on multiple occasions over the years, testing the patience of long-term investors.

Many of NVIDIA's gains have been made in the past couple of years, driven by accelerating revenue and earnings growth. The gaming business has been strong, in part due to AMD's lackluster performance. But NVIDIA has also diversified, pushing its GPUs to be used for enterprise computing and automotive applications. The company began investing in machine learning and artificial intelligence early on, and that foresight is paying dividends today. During NVIDIA's latest quarter, its data center segment nearly tripled revenue year-over-year, coming close to a $1 billion annual run rate.

NVIDIA's graphics chips are increasingly being used to accelerate workloads, and its automotive platforms are positioned to be an integral part of the self-driving car of the future. The stock is extremely expensive after gaining so much over the past few years, trading at the highest multiple of sales since its IPO. This may make continued gains tougher to achieve, but the company itself is firing on all cylinders.

Becoming a coffee giant

Starbucks wasn't always so ubiquitous. While it's hard to go anywhere today without being tempted by a mocha Frappuccino, Starbucks hit a rough patch during CEO Howard Schultz's absence last decade. Schultz was CEO up until 2000, when he stepped down to focus on global strategy. Schultz had grown the company from 45 stores to more than 2,800 since it was founded.

Schultz returned in 2008 following a steep decline in the stock and fears that Starbucks was losing its edge. Schultz aimed to make going to Starbucks an experience, and he succeeded in a big way. Starbucks is now the undisputed king of coffee, with over 24,000 locations worldwide. It's early embrace of mobile payments has kept it one step ahead on the technological front, and its successful rewards program engenders intense loyalty.

SBUX Total Return Price Chart

SBUX Total Return Price data by YCharts

Including dividends, Starbucks stock has returned about 18,000% since its IPO in 1992, turning a $10,000 investment into nearly $2 million. Achieving that return required holding onto the stock during the turmoil of the mid-2000s, when investors suffered a loss of more than 75%. But those who bought only during the past few years have enjoyed a market-beating return, driven by Starbucks' expanding revenue and profit.

Starbucks stock is expensive, although not to the same degree as NVIDIA. The stock trades for around 30 time earnings, a steep price for sure, but one that's not too difficult to justify given the company's track record. Schultz plans to step down in April, turning his focus to the company's high-end Reserve business. With Starbucks in a much stronger position today, the company should be fine without Schultz at the helm.

Timothy Green has no position in any stocks mentioned. The Motley Fool owns shares of and recommends Nvidia and Starbucks. The Motley Fool has a disclosure policy.