Coffeehouse Post

Single Post Permalink

View Thread: is managed code faster than native?
  • User profile image


    Well I was throwing different examples in there, so different approaches are required in each case.

    To simplify things, for this example let's just say I'm implementing a DSP algorithm in C#. In that case there is quite a big difference in using for vs foreach. In my algorithm I analyze the FFT results, then classify peaks based on certain criteria. Then there are additional algorithms that enumerate over those results and analyze the musical relationships between all the collected peaks. So as you can see, there is a lot of looping.

    What I have found is that the performance increase when switching to for loops from foreach loops is roughly 30%.

    The IO example is a bit more complex because just profiling a specific part of the management code itself (C++) has shown that that part also had a roughly 30% increase in performance when going to simple integer indexing. Now the IO in other parts of the code is a much bigger bottleneck, however changing the management code to use integer indexing resulted in an overall improvement of 5% or so. Not as big but still worthwhile.

    BTW in this particular case the DSP algorithm needs to run on WP7/8. As such I can't use the GPU. I can use C++ on WP8 however to keep it backwards compatible with WP7, I prefer not to do that. The point is that with the right coding approach it is fast enough that I don't need to resort to something else.