What is more haram, masturbation for men or a man having a friendship with a woman?

One should not look at the size of the sin but whom he is sinning against. Instead of choosing between two haram actions you could have a temporary marriage with a suitable woman.

May Allah ease your situation.