Wall Street has grown particularly bullish over semiconductor companies Advanced Micro Devices (AMD -0.17%) and Nvidia (NVDA 1.75%) this year, with both stocks up more than 90% since Jan. 1. The rallies have primarily been fueled by a boom in artificial intelligence (AI) and expectations that chipmakers have the most to gain from the industry's development.

According to data from Grand View Research, the AI market is projected to expand at a compound annual growth rate of 37% through 2030 after hitting $137 billion last year. As a result, AMD and Nvidia still have plenty of room for growth over the long term despite their recent rallies. So it's not a bad time to consider investing in one of these tech companies before it's too late. 

However, before you do, let's look at whether AMD or Nvidia is currently the better buy.

Advanced Micro Devices: An increasingly diverse business

AMD is an attractive investment option thanks to the diversity of its business. The chipmaker has carved out solid positions in multiple markets by partnering with several high-profile tech companies. For example, AMD's chips exclusively power Sony and Microsoft's current generation of game consoles, cloud platforms such as Azure and Alphabet's Google Cloud, and countless other devices such as laptops and handheld gaming machines.

Meanwhile, AMD is expanding to other areas of tech. Last year, the tech giant acquired Xilinx, a company developing processors for specialized uses such as space, industrial, AI, and aerospace and defense. The purchase has further diversified AMD's earnings and boosted its embedded segment, with revenue rising more than 1,700% year over year in 2022.

Moreover, AMD has promising prospects in the future of AI. The company seemed to have a weaker start in the market than Nvidia. However, AMD CEO Lisa Su is highly motivated to change all that. The top executive said in May, "If you look out five years, you will see AI in every single product at AMD, and it will be the largest growth driver."

The company's potential in AI has only grown stronger since it collaborated with Microsoft, which is bolstering AMD's AI chip expansion through financial and engineering resources in an effort to create an alternative to Nvidia's offerings.

Nvidia: A lead in artificial intelligence

When a boom in AI was kicked off last November by the launch of OpenAI's ChatGPT, investors turned to Nvidia as an obvious way to back the burgeoning market. The company is the leading supplier of chips to ChatGPT and Amazon Web Services, the world's largest cloud platform. With the cloud market likely to receive a boost from increasing demand for AI services, Nvidia bulls have sent the company's shares skyrocketing 165% year to date.

As a result, Nvidia has a lot of work ahead to retain its position at the top and live up to its high valuation.

Since its founding in 1993, Nvidia has made a name for itself by producing top-of-the-line graphics processing units (GPUs), being one of the first to make these chips available to the consumer market. The chips led millions of consumers to build custom PCs powered by Nvidia GPUs.

However, the company has since used its dominance in the space to expand into less consumer-reliant markets such as AI and cloud computing. Its efforts have paid off, with its data center segment now earning the largest portion of revenue and growing 41% year over year in 2022.

A report from TrendForce revealed in March that ChatGPT alone utilized 20,000 graphics processing units (GPUs) in 2020, which is expected to hit 30,000 as its user base rises. If Nvidia can retain its lead over AMD and become a go-to for AI companies seeking powerful chips long term, its stock could soar even further in the coming years.

Is AMD or Nvidia the better buy?

A lot is still up in the air with the future of AI, so it's impossible to know whether AMD or Nvidia is likely to benefit more from the market. Both companies are likely to snap up market share as the industry expands, making an investment in either company an attractive move.

However, looking at these companies' businesses in their entirety, AMD is the better buy. Different areas of its business are more diverse than Nvidia's, making it the more reliable investment. For instance, when it comes to consumer chip offerings, AMD is excelling at GPUs and central processing units, while Nvidia is almost all-in on GPUs. Even AMD's game console business is more varied, partnering with Sony, Microsoft, and Valve. Meanwhile, Nvidia's main source of console gaming revenue is from Nintendo's Switch console.

Furthermore, AMD is in better financial standing based on its price-to-free cash flow ratio (P/CF) of 80, compared with Nvidia's 190. Both figures are higher than what is considered a bargain. However, AMD's lower P/CF suggests it is in better standing and a better buy right now.