Everyone knows that Warren Buffett's company Berkshire Hathaway (BRK.A -0.34%) (BRK.B -0.01%) has been a superb investment since Buffett took over the company in 1965. The stock has soundly beaten the broader market by a wide margin over that time. But it's also a good idea to look at how Berkshire has performed over different periods of time, such as the 21st century, through different economic cycles, and different periods of market turbulence.

That's why I was interested in examining Berkshire's performance over the last few years, because 2021 was a time when the market exploded higher, only to be followed in 2022 by an extremely difficult market. If you invested $4,000 at the very beginning of 2021, here's how much you would have today.

Buffett's still got it

Given that Buffett is 92 years old, many people have questioned whether the Oracle of Omaha still has the magic touch. After all, as managers and CEOs get older, they might be more reluctant to adapt to modern-day trends, especially when they've had so much success doing things their way for decades.

But experience is often overlooked, and Buffett and Berkshire demonstrated just how much experience they had in 2021. The market got very frothy because consumers had tons of excess savings and the Federal Reserve was pumping liquidity into the economy at an unprecedented clip. Scores of companies went public and special purpose acquisition companies (SPACs) were all the rage.

But as investors were buying at what would ultimately be a peak for the market that may be difficult to get back to in the near term, Berkshire remained patient and disciplined, selling many more stocks than it bought in 2021. Instead, Berkshire spent roughly $27 billion to buy its own stock while, in Buffett's opinion, it traded below its intrinsic value, which is part of Buffett's core value investing philosophy.

Even with its discipline, Berkshire's stock slightly outperformed the broader market in 2021, rising 29.6% and edging out the S&P 500's 28.7% gain. In 2022, Berkshire's patience and resilience would pay off, and the company would show that it could perform well in a variety of economic environments.

As the Fed found itself behind the curve on inflation, the agency moved fast, raising interest rates intensely, much to the surprise of the market. This crushed riskier growth and tech stocks that were trading at high valuations and led investors scrambling for where to put their money, if anywhere at all. Berkshire, with its wide exposure to a variety of different industries, several of which could hedge inflation, became an attractive spot.

Berkshire was also much more active in 2022, purchasing close to $68 billion worth of stocks, much of which occurred early in 2022, although Berkshire also sold $33.7 billion worth of stocks as well. The company made big purchases in U.S. domestic oil companies such as Occidental Petroleum right around the time when Russia's ongoing invasion of Ukraine began. Berkshire only repurchased $7.9 billion of its own stock in 2022.

Last year, Berkshire thumped the broader market, with its stock up 4% in 2022 compared to the S&P 500's 18% loss.

If you had invested $4,000 in 2021...

As you can see, Warren Buffett and the team at Berkshire Hathaway are still some of the best in the business. In hindsight, the company showed great patience and made some great moves during a very difficult, chaotic period for the markets.

Since the very beginning of 2021, Berkshire's stock is currently up more than 41% and has crushed the broader market. The S&P 500 is up about 10%, including dividend reinvestment, and the Nasdaq Composite is down about 5%. This means that $4,000 invested into Berkshire stock at the very beginning of 2021 is now worth $5,652 in a little under two and a half years.