Nvidia (NVDA 6.18%) and Palantir (PLTR 3.73%) operate in different sectors, but both tech companies are profiting from the secular expansion of the artificial intelligence (AI) market.

Nvidia's GPUs are often associated with video games, but a growing number of data centers are installing its high-end GPUs to process AI tasks. Palantir's data mining platforms accumulate and process data from disparate sources to help government agencies and big companies make AI-driven decisions.

Both companies have generated impressive gains over the past 12 months. Nvidia's stock more than doubled as it continued to sell more gaming and data center GPUs. Palantir's stock soared about 160% as it dazzled investors with its robust revenue growth rates and optimistic long-term targets. But should investors who missed those gains consider buying either stock right now?

The back of an android's head shattering.

Image source: Getty Images.

Nvidia's core growth engines are firing on all cylinders

Nvidia's revenue rose 53% to $16.7 billion in fiscal 2021, which ended this January, while its adjusted net income soared 75% to $6.3 billion. Its adjusted gross margin expanded 310 basis points to 65.6%.

In the first half of fiscal 2022, Nvidia's revenue soared another 75% year-over-year to $12.2 billion as its adjusted net income surged 99% to $4.9 billion. Its adjusted gross margin expanded 50 basis points to 66.4%. This growth was primarily driven by its gaming and data center GPU businesses, which generated 83% of its revenue last quarter.

Its gaming GPU business benefited from higher video game sales throughout the pandemic and the usage of some of its chips to mine cryptocurrencies, while a growing hunger for AI services boosted the data center market's demand for its high-end GPUs. Nvidia's takeover of the networking hardware maker Mellanox last year also boosted its data center revenue.

Analysts expect Nvidia's revenue and adjusted earnings to increase 55% and 65%, respectively, for the full year. Nvidia is exposed to the global chip shortage, since it's a fabless chipmaker that relies on third-party foundries, but its rising market prices are offsetting those slower shipments.

Palantir continues to silence the bears

Palantir's revenue rose 47% to $1.1 billion in 2020 as its government and commercial revenues rose 77% and 22%, respectively.

It posted a net loss of $1.17 billion, mainly due to $1.27 billion in stock-based compensation expenses, but its adjusted operating margin improved from negative 45% to positive 17%.

The bears initially claimed Palantir would remain heavily dependent on rigid government contracts, the growth of its commercial revenue would decelerate, and it would remain deeply unprofitable.

But in the first half of 2021, Palantir's revenue jumped 49% year-over-year to $717 million as it secured new government contracts and accelerated the growth of its commercial business. Its net loss widened again, from $165 million to $262 million, but its adjusted operating margin rose to 33% as its adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA) jumped from $20 million to $241 million.

Wall Street expects Palantir's revenue to rise 38% this year, while the company plans to generate "at least" 30% annual revenue growth from 2021 to 2025. Palantir believes its data mining platform -- which already serves dozens of government agencies -- will become the "default operating system" for data within the U.S. government. It then expects that battle-hardened reputation to draw more enterprise customers to its platform.

The valuations and challenges

Nvidia trades at 55 times forward earnings and 25 times this year's sales. Those valuations might seem high, but they're fairly reasonable relative to Wall Street's rosy expectations for the company.

However, investors should note that Nvidia's $40 billion bid for Arm -- which would add the world's top mobile chip designer to its portfolio -- could still collapse amid regulatory challenges. If that happens, Nvidia's stock could slip as investors reevaluate its future without Arm's licensing business.

Palantir trades at 34 times this year's sales. That valuation also seems high, but it could be justified if Palantir achieves its target of generating more than 30% revenue growth over the next four years.

But several headwinds -- including competition in the enterprise market, the loss of future government contracts, and the public's scrutiny of its secretive deals with government agencies -- could still limit its long-term gains.

The winner: Nvidia

Palantir might be a more direct play on the AI market than Nvidia, but it's a much riskier investment. Nvidia is better diversified, more profitable, and faces fewer controversies, and its stock is significantly cheaper.

Both of these stocks will likely benefit from the secular expansion of the AI market, which Grand View Research expects to expand at a compounded annual growth rate (CAGR) of 40.2% from 2021 to 2028. But if you can only buy one of these high-growth tech stocks, I would stick with Nvidia.