With the market well within bear market territory, many investors may wonder if it's time to pull money out of the market. However, I think the wiser move is to buy stocks.

While the short-term prospects may look grim, the long-term picture remains intact for many companies, including Alphabet (GOOG -1.96%) (GOOGL -1.97%) and Autodesk (ADSK 0.65%). So if you've got some cash on the sidelines, picking up a few shares of these two companies could make you look like a genius a few years later.

1. Alphabet

Alphabet is the parent company of YouTube, the Android operating system, and a wide range of Google products. While that may seem like a diversified company, it's highly concentrated on advertising. In fact, Alphabet derives more than 80% of its revenue from advertising sources.

Businesses everywhere are slashing advertising budgets, with the economy trending toward a recession. That's because it's a manageable expense to trim compared to layoffs or cutting projects.

Even so, in the second quarter, Alphabet managed to grow its revenue by 13% year over year. On Oct. 25, investors will learn how Alphabet did in the third quarter. However, 28 analysts project 8.9% sales growth in Q3. So even in this increasingly challenging environment, Alphabet will likely continue its growth.

As for profits, Alphabet saw its earnings per share slip by $0.15 to $1.21 in Q2. Alphabet's CEO Sundar Pichai has already discussed cost-cutting measures and hiring slowdowns; I'd expect the earnings growth to return eventually.

When advertisement spending returns as the economy recovers, Alphabet's cost-cutting measures will still be in place. At that time, I'd expect Alphabet's stock to rise rapidly.

As for now, Alphabet's stock trades at a bargain valuation of 16.2 times earnings. Compared to the S&P 500's 17.4 price-to-earnings (P/E) ratio, Alphabet is trading at a slight discount to the market.

Alphabet is a market leader in advertising and still growing at a time when many S&P 500 constituents will be shrinking. I think now is an excellent opportunity to take a position in Alphabet's stock, especially with it down more than 30% from its all-time high.

2. Autodesk

Unlike Alphabet, Autodesk does not rely on advertisement revenue. Instead, its software is purchased on a subscription basis. Engineers and architects utilize Autodesk's products daily to accomplish their jobs, making it an indispensable product and one they cannot cancel.

Because of the subscription product, Autodesk can continuously raise its prices in good times and bad. This power was reflected in the COVID-19-induced recession.

Chart showing Autodesk revenue growth during the Great Recession and during the COVID-19 pandemic.

Image source: Autodesk.

Even though the COVID-19 recession was short, what is ahead will likely be much longer, or a recession may not surface at all. Regardless, the subscription model will thrive.

In Autodesk's Q2 fiscal year 2023 (ended July 31), revenue rose 17% from a year ago. Additionally, its non-GAAP (adjusted) operating margin increased by five percentage points to 36%.

That's strong results in a tough environment, but management expects solid double-digit revenue and free cash flow growth through fiscal year 2026 (Jan. 31, 2027). Subscription revenue is much easier to predict, making forecasting growth and expenses more straightforward, thus leading to efficiency increases.

With Autodesk's vital product, predictable growth, and efficiency measures, it's an outstanding stock to own. It's also reasonably priced at 25 times forward earnings.

Autodesk is a top stock to buy right now because, regardless of what happens with the economy, it will maintain its growth solely due to its business model.