I have both the 335i and M3, also had a 328i before all in the e9x family. I can say they are completely different cars. The 335 is a great daily, plenty of torque low in the rpm range, easily modified to silly performance figures but the turbo engine just isn't as smooth as a N/A engine nor does the 6at box shift the way m-dct does (if manual it may be a different story and I don't have a 335is so i can't comment on how the regular DCT shifts). For the price of the 335i/is, there isn't any other cars that will perform better.
As for the M3, the moment you start it up it just sounds and feels different from the 335. I must admit, at normal city speeds it felt very similar to my old 328; however, once you press the "m" button OR rev the engine past 4000rpm, it just turns into a whole different animal. I also really like the EDC feature being able to switch between comfort, normal, and sport.
In the 335 revving past 5000rpm almost seem pointless as it drops out of the peak torque range. The M3 just keeps feeling more and more powerful all the way to 8000rpm. The first few weeks/months of driving I would shift and end up realizing i still had another 1000rpm to go and when I started to take advantage of the entire rpm range, no words can describe it (this is one thing that each individual driver have to feel to know it).
So at the end of the day, I use to think exactly like the OP that the 335i/is is the better all round performer than the M3, but after one test drive in the M3, I immediately put a deposit down and I just had to have it. I was COMPLETELY wrong in thinking that 335i > M3.
To the OP, I would suggest you to drive the 335i/is and M3 back to back on city roads and highway. On paper, the performance figure isn't all that different but it real life, BMW did not make a mistake/screw-up in producing two amazing cars in the 3-series range but they created two completely different cars to cater to different drivers.
11 E90 ///
12 Range Rover Autobiography
06 Porsche Cayenne S
09 E92 335xi M-sport SOLD
08 E90 328xi Gone but will never be forgotten!