This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Optimising C++

I've ported some code from C to C++ and I'm shocked at how much more slowly it runs. I've written a lot of C++ in the past, so I know I haven't done anything absurdly inefficient, but execution times have gone up by 150% (2.5 times slower!). Has anyone else seen anything like this? Are there any particular aspects of the Keil C++ implementation that I should look out for?

Parents
  • "When program optimization comes to the point of trying to figure out what code the compiler likes the most, it all begins to look rather silly."

    Absolutely - the whole point of using a HLL is to make life easier (some say, "more productive") for the Programmer.
    Clearly the C++ is failing in this!

    "It's a perfect candidate for implementation in assembly language."

    Or, if the original 'C' performance was OK, why not leave it in plain 'C'?

Reply
  • "When program optimization comes to the point of trying to figure out what code the compiler likes the most, it all begins to look rather silly."

    Absolutely - the whole point of using a HLL is to make life easier (some say, "more productive") for the Programmer.
    Clearly the C++ is failing in this!

    "It's a perfect candidate for implementation in assembly language."

    Or, if the original 'C' performance was OK, why not leave it in plain 'C'?

Children
  • Well the original C code wasn't fast enough either! The 48 bit comparisons can probably be done really quickly in assembler, and wouldn't cause code bloat if inlined. I'm probably going to accelerate it in an FPGA at the end of the day.

    As for re-coding for speed, I think it's a reasonable thing to do if you get enough benefit for the effort involved. It's not the worst solution in the world.