Recession fears sent the S&P 500 (^GSPC 1.02%) tumbling into a bear market last year, and the benchmark index is still down 8%. But patient investors have nothing to fear from a recession. History says the economy will regain its momentum in time, and the S&P 500 will find its way back to bull market territory, buoyed by secular trends like artificial intelligence (AI).

Indeed, consultancy McKinsey estimates that AI could boost global economic output by $13 trillion by 2030, and Ark Invest estimates that AI software sales will increase at 42% annually during that time period. Many companies will benefit as AI becomes more prevalent, but investors should take a close look at Datadog (DDOG 4.95%) and Cognex (CGNX 2.06%) right now.

Shares of Datadog and Cognex are currently down 51% and 41% since 2020, respectively, but both businesses are bursting with potential. Here's why these growth stocks are worth buying today.

1. Datadog

Digital transformation helps enterprises stay relevant and better serve their customers, but it also makes IT environments more complex. Enterprises depend on an ever-growing number of software systems, and they are often spread across private data centers and public clouds. Keeping those systems performant and secure is critical.

Datadog provides observability and security software that gives clients real-time visibility across their IT infrastructure, helping them identify and resolve performance and security issues. Its platform integrates more than a dozen different software products and it features more than 600 turnkey integrations that simplify deployment. Its software also leans on artificial intelligence (AI) to automate anomaly detection, root cause analysis, and incident alerts, which ultimately helps development, operations, and security teams work more efficiently.

Datadog reported reasonable financial results in the first quarter, especially in the context of difficult economic environment. Its customer count climbed 29% and the average customer increased spend by more than 30%, evidencing the value created by its platform. In turn, revenue climbed 33% to $482 million and non-GAAP earnings rose 17% to $0.28 per diluted share.

Looking ahead, Datadog is well positioned to maintain or even accelerate its growth trajectory as economic conditions improve. Industry experts have recognized its leadership in several observability software verticals. For instance, consultancy Gartner says Datadog is a leader in application performance monitoring, Forrester Research says the company is a leader in AI for IT operations, and G2 says Datadog a leader in cloud infrastructure and server monitoring.

The company has also displayed a remarkable capacity for innovation throughout its history, adding new products to its portfolio on a regular basis. That quality, coupled with the growing need for observability and security software, is driving its total addressable market (TAM) higher. Datadog believes its TAM will reach $62 billion by 2026, up from $41 billion in 2021.

Currently, shares trade at 16.9 times sales, a bargain compared to the three-year average of 37.7 times sales. That multiple is far from cheap, but high-quality businesses like Datadog often command premium valuations, so investors should take advantage of the discounted price. Now is a good time to buy a small position in this growth stock.

2. Cognex

Cognex specializes in industrial machine vision, a technology that uses cameras and AI software to give factory equipment the ability to see, recognize, and analyze objects. Its machine vision systems are most commonly used in automotive, electronics, and logistics end markets, where they identify, measure, and inspect parts and packages to automate the manufacturing, distribution, and quality assurance processes.

Hardware vendors like Cognex tend to be cyclical businesses, meaning they typically see periods of expansion followed by periods of contraction, simply because customers can go years without refreshing their hardware. The cyclical nature of the machine vision industry was particularly evident over the last year. Many e-commerce businesses invested heavily in logistics infrastructure during the pandemic, but they have since cut spending to absorb excess capacity.

That cyclicality was further magnified by the uncertain economic environment, which caused businesses to pull back more sharply on spending than they otherwise would have. That translated into disappointing financial results for Cognex in the first quarter. Revenue declined 29% to $201 million and net income dropped 61% to $0.15 per diluted share. But investors have good reason to believe Cognex can reaccelerate growth in the future, and the stock could explode during the next expansionary phase of the business cycle.

Cognex is the market leader in industrial machine vision systems, software, sensors, and barcode readers. The company currently values its addressable market at $6.5 billion, and it believes that figure will grow at 13% annually over the long term. But management is guiding for long-term revenue growth of 15% annually, meaning Cognex is confident in its ability to take share and reinforce its market leadership.

With that in mind, shares trade at 10.5 times sales, a discount to the three-year average of 12.1 times sales. That creates a reasonable buying opportunity for patient investors.