The stock market is a time-tested way to build wealth, but getting started can be intimidating. With thousands of public companies and countless financial metrics to consider, building a portfolio requires a lot of work. And deciding which stocks to buy is only half of the battle. Investors also need to keep tabs on those stocks, which means reading financial reports and staying up to date on relevant events.

Fortunately, there are easier ways to become a stock market millionaire. Here are two great index funds that can help you achieve that goal.

1. Vanguard S&P 500 ETF

The S&P 500 tracks the performance of 500 of the largest U.S. companies. Its components span all 11 market sectors, though three sectors -- information technology, healthcare, and consumer discretionary -- account for 52% of the its weight. Thanks to its broad scope, the S&P 500 is often viewed as a proxy for the entire U.S. stock market.

Over the last three decades, the S&P 500 has generated a total return of 1,770%, which is equivalent to an annualized return of 9.9%. At that pace, $100 invested on a weekly basis would grow into a $1 million portfolio in just under 32 years.

That makes an S&P 500 index fund, such as the Vanguard S&P 500 ETF (VOO 0.87%), a very compelling investment idea. Shareholders benefit from instant diversification, and with an expense ratio of just 0.03%, the annual fee on a $10,000 portfolio would be just $3. Better yet, investing in an S&P 500 index fund requires virtually no work. And shareholders can sleep easy knowing that, while the stock market has crashed many times, the S&P 500 has always recouped its losses and gone on to hit new highs.

2. Invesco QQQ Trust

The Nasdaq-100 tracks the performance of 100 of the largest non-financial companies listed on the Nasdaq stock exchange. Unlike the S&P 500, it includes both U.S. and international stocks, and its sector allocation looks quite different. Information technology (IT) companies alone comprise 50% of its weight, and the top three sectors -- IT, consumer discretionary, and communications -- account for 82% of its weight.

The Nasdaq-100 has not been around as long as the S&P 500, so less historical data is available. But the index has generated a return of 1,180% over the last two decades, which is equivalent to an annualized return of 13.6%. At that pace, $100 invested on a weekly basis would grow into a $1 million portfolio in just under 26 years.

That makes a Nasdaq-100 index fund like the Invesco QQQ Trust (QQQ 1.01%) a smart choice for investors that are bullish on the tech sector. It offers many of the same benefits as an S&P 500 index fund -- instant diversification and very little work -- but the Nasdaq-100 has more than tripled the return of the S&P 500 over the last two decades.

As a caveat, that outperformance comes at a price. Due to its tech-heavy composition, the Nasdaq-100 has historically been more volatile than the S&P 500. The current situation is a great example. High inflation and rising interest rates have dragged both indexes down this year, but the Nasdaq-100 is currently 27% off its high, while the S&P 500 is down just 18%.

Also noteworthy, the Invesco QQQ Trust has a higher expense ratio of 0.2%, meaning the annual fee on a $10,000 portfolio is $20.

The secret to making money in the stock market

Investors need just two things to make money in the stock market: patience and commitment. Stock prices rise and fall in response to countless factors, and investors may be tempted to sell or to stop contributing to an index fund during a downturn. But attempting to time the market can be a very costly mistake.

The S&P 500 and the Nasdaq-100 have the capacity to create tremendous wealth over time. Investors just need to be patient and stay the course. That means investing on a regular basis, regardless of whether the indexes are rising or falling.