S&P started at $17.57 in January of 1928. The latests S&P is now about $6,916.
Gold started a $20 an ounce. Now Gold is above $5,000.
In the S&P, there have been dividends during this time. No dividends from a gold ounce.
But the S&P 500 changes over time. Companies are added. This changes the overall return.
It is not at all clear gold outperformsthe S&P. In fact, It seems the S&P probably outperforms gold, even today, and almost certainly the S&P outperforms gold for most of the time.
You can pick periods where gold does better than stocks, and periods where stocks do better than gold. It’s all hype.