There is no better vehicle for creating wealth than investing in stocks. They beat out gold, bonds, real estate, and certainly cryptocurrencies. And while one asset class or another may outperform stocks over short periods of time, history proves that if you want to accumulate large amounts of wealth, investing in stocks is the way to go.

A Deutsche Bank study showed that over the past 100 years, stocks surpassed the performance of gold by 5.6% annually, housing prices by 6.6%, Treasuries by 6.8%, and oil by 8.4% per year.

Pile of $100 bills.

Image source: Getty Images.

Only twice have there been a decade when stocks produced negative returns: the 1930s, when the market lost 0.5% during the Great Depression, and the 2000s, when a combination of the Tech Wreck, 9/11, and the financial and housing markets collapse conspired to sink the market and caused stocks to lose 0.9%.

Yet, those losing periods were followed by strong bull markets. The 1940s generated compound annual returns of 10.2% annually, including dividends, while the 2010s produced a CAGR of 14%.

Tech stocks have often been the driver of the market's gains as demand for consumer electronics and related products and services caused the sector to far outperform every other segment. So buying and holding tech stocks for the long haul is the way to go. Following are two you should consider now.

Apple

Whether or not you're a fan of Apple (AAPL 1.27%) products, you must admit it operates a superior business. When it's not changing how consumers think about interacting with technology, it's producing products with a style, fit, and finish that capture a large number of customers within its ecosystem. And analysts continuously underestimate the power of that allure, which has them often misjudge the staying power of its gadgets.

Warren Buffett understands the iconic prestige of the brand and its ability to generate recurring streams of revenue and profits over long periods of time. While I don't recommend making Apple stock almost half of your portfolio, as Buffett has done at Berkshire Hathaway, it's still a company an investor can't go wrong with over the decades.

Revenue continues to run higher, with second-quarter sales eclipsing $83 billion, a record for the period, as product revenue rose 7% to $77.5 billion, and service revenue jumped 17% to $20 billion, also a record.

The iPhone, in particular, but also its Macs, iPads, Apple Watch, and Apple TV continue to grow in popularity. However, it's that service portion of its business that is likely to be the company's future as it is the fastest-growing segment. It makes Apple a stock to buy now and hold onto for decades.

Digital Realty

A real estate investment trust (REIT) isn't what you normally think of as a tech stock. However, because Digital Realty Trust (DLR 1.50%) is the world's largest provider of data centers for cloud services and telecom carriers, this REIT easily fits the bill.

Data centers are considered the backbone of the internet -- the central nervous system for every device that accesses a network, whether in the cloud or online. For speed and efficiency, data needs to be housed in a central depository, and data centers serve as secure warehouses for the servers and networking equipment storing the data.

Digital Realty owns over 300 data centers in 27 countries, representing nearly 37 million square feet of space. The industry has undergone significant consolidation that has left the REIT as one of only two remaining that focus on the sector.

Data centers used to be solely physical facilities, but they're increasingly being located in the cloud themselves. Digital Realty's PlatformDigital service offers a hybrid solution of cloud and brick-and-mortar storage options that growing numbers of customers are using.

The REIT lowered its core funds-from-operations guidance for the full year by $0.05, to $6.75 to $6.85 per share, but that downward shift is due solely to currency exchange rates.

Digital Realty customers like Amazon and Microsoft could become competitors down the road, considering their own vaunted cloud services. But as more businesses generate growing amounts of data, the need for the REITs' specialized services is likely to keep pace. Global expansion makes Digital Realty a stock to own now and well into the future.