Comparing yourself to others can be detrimental to your mental health.
But this isn't always the case.
It can sometimes be crucial for your personal development.
What you choose to compare matters more than the act of comparing itself.
For example, comparing your outcomes to someone else's is not helpful.
It does not teach you how to improve and often facilitates your negative self-beliefs.
Comparing your circumstances with others also does very little for your personal growth. This is easy to do and for many, has become a habit.
But you must learn to avoid it.
Instead, you should compare your habits to those of people achieving what you desire. Analyse what they do consistently and how that helps them achieve more.
This is a much healthier thing to compare. It allows you to make small changes based on your needs and circumstances.