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
  • There's too much code to post, but here's an overview.

    The purpose of the function is to look for an address range (start address to end address) in a list of allocated address ranges. This involves doing a lot of address comparisons, where the addresses are 48 bits long. The C code uses a structure to hold the address which consists of an upper 16 bits and a lower 32 bits, and a function is called to compare structures.

    The C++ implementation defines a class with the same member variables as the old C structure. Operator methods are the defined for the >= and <= operators, which perform the same comparison as the old C comparison functions. The operators use "pass by reference".

    As the data and functions are fairly similar between C and C++, I wasn't expecting a huge difference in execution speed. I've had a quick look at the intermediate C produced by the C++ preprocessor, and it's virtually unreadable. I might have to give it more mental effort, but pointers in the right direction would be appreciated.

Reply
  • There's too much code to post, but here's an overview.

    The purpose of the function is to look for an address range (start address to end address) in a list of allocated address ranges. This involves doing a lot of address comparisons, where the addresses are 48 bits long. The C code uses a structure to hold the address which consists of an upper 16 bits and a lower 32 bits, and a function is called to compare structures.

    The C++ implementation defines a class with the same member variables as the old C structure. Operator methods are the defined for the >= and <= operators, which perform the same comparison as the old C comparison functions. The operators use "pass by reference".

    As the data and functions are fairly similar between C and C++, I wasn't expecting a huge difference in execution speed. I've had a quick look at the intermediate C produced by the C++ preprocessor, and it's virtually unreadable. I might have to give it more mental effort, but pointers in the right direction would be appreciated.

Children