Having owned a 335xi and driven many M3s, I can say they are two different cars in 2 different price points.
If I could have afforded the E92 M3 when I bought my E90 335, I would have gone M3.
Loved my 335 & they are cheaper to make fast if that is your goal. When I had the cash to buy the M3, I was no longer shopping for one. I was looking at an E60 M5 or C6 Vette & went with the Vette.