September is historically the worst month for the S&P 500. However, August wasn't a great one. The major index slipped 1.5% lower after delivering a 19.5% gain in the preceding seven months.

Even with the S&P 500 stumbling somewhat, there were a few winners. Should you still buy the S&P 500's best-performing August stocks? Here they are, along with their pros and cons.

1. Arista Networks

Arista Networks' (ANET -0.02%) shares jumped nearly 26% in August. That was enough to make the network-equipment stock the best performer in the S&P 500 for the month. Arista stock has soared more than 60% so far this year.

Nearly all of Arista's big gain in August came on the first day of the month. The company announced its second-quarter results after the market closed on July 31, 2023. Arista reported record revenue and earnings growth in Q2. 

Organizations continue to move their apps and data to the cloud. The surging interest in artificial intelligence (AI) provides an even bigger tailwind for Arista. The company now expects to deliver annual-revenue growth of around 30% going forward, up from its previous forecast of 25% growth.

Arista faces plenty of competition, notably with companies including Cisco and Juniper Networks. Its stock is also relatively expensive, with shares trading at 28.5 times expected earnings. However, I think Arista remains one of the better ways to play the AI-fueled cloud opportunity. 

2. Eli Lilly

Eli Lilly (LLY 1.19%) ranked as the second-biggest winner among S&P 500 stocks in August. Shares of the big drugmaker soared 22% last month and are up 60% year to date.

The primary catalyst for Lilly in August was the company's Q2 update. Lilly announced strong Q2 results and raised its full-year revenue guidance by $2.2 billion. Around $1.5 billion of the guidance increase stemmed from business development (including three acquisitions that closed just days after Lilly reported its Q2 earnings).

There are several reasons for investors to consider buying this big pharma stock. Mounjaro stands at the top of the list. The drug is already Lilly's greatest growth driver as a treatment for type 2 diabetes. The company awaits regulatory approval for Mounjaro in treating weight loss. Some analysts project that Mounjaro could become the biggest-selling drug of all time.

The main knock against Lilly is that significant growth is already priced into its share price. The stock trades at a sky-high forward price-to-earnings ratio of 46 times. 

I wouldn't bet on Lilly's momentum continuing at the pace seen so far this year. However, I think this stock should still have room to run and is a good pick for long-term investors.

3. Global Payments

Shares of Global Payments (GPN -0.05%) vaulted nearly 15% higher in August, making the stock the No. 3 top S&P 500 performer for the month. The payments-technology stock has risen close to 27% year to date.

As was the case with Arista Networks and Eli Lilly, Global Payments' Q2 update served as its major catalyst in August. The company reported year-over-year net-revenue growth of 7% with adjusted earnings per share jumping 11%. Even better, Global Payments raised its full-year net-revenue and earnings guidance.

Probably the main plus for Global Payments is that digital payments will almost certainly continue to grow over the next several decades. The rise of middle classes in emerging markets should especially provide a boost. 

The stock is also attractively valued right now. Its shares trade at a forward-earnings multiple of only 10.6 times and a price-to-earnings-to-growth (PEG) ratio of 0.64. 

However, Global Payments' fortunes hinge largely on macroeconomic factors. If fears of a recession resurface, the fintech stock could falter. I still think, though, that Global Payments is a stock that long-term investors should seriously consider buying.