Does using delegates slow down my .NET programs?

前端 未结 4 2055
小鲜肉
小鲜肉 2020-12-06 10:20

Does using delegates slow down my programs?

I\'ve been avoiding them because I really have no clue if they make my programs any slower. I know if I cause a (catch

4条回答
  •  抹茶落季
    2020-12-06 10:46

    I work on Windows CE so this kind of thing is sometimes a little more pertinent. For example a brash application of reflection can really hurt so we tend to avoid reflection where sensible (obviously small applications of reflection are fine). Obviously I do no such madness on desktop.

    I've heard people murmour about delegates and CE performance but as far as i'm concerned its utter guff. I heard that it "slows down the method call by 30%" but if thats 30% of a crappy algorithm then whose fault is that? Another slow down in CE is virtual methods, as there is no lookup table it manually works them out first time and caches the result. This means if you piss away all your memory those caches will be purged and it will result in a perf hit next time round. But that considered, should you throw away useful OOP skills for the sake of performance?

    I find that a lot of these "OMG don't use that it's too slow" are just excuses. Mainly excuses because people don't know whats really wrong with their app and its easy to blame some internal working of the CLR instead of their own code. If your performance sucks then I'd reckon that 99.9% of the time you can change something in your part of the app or design that doesn't throw away tools and results in much better improvements.

提交回复
热议问题