telecom • networking • design

an blog

1 Comment

Optimize C and C++ Code

Optimize C and C++ codeWith the advent of mobile devices, optimizing code has become even more important. Faster applications not only improve the user experience, they also improve battery life.

Optimizing C++ and C Code discusses several techniques that will help improve the performance.

  1. Premature optimization is the root of all evil
  2. Adjust structure sizes to power of two
  3. Place case labels in narrow range
  4. Place frequent case labels first
  5. Break big switch statements into nested switches
  6. Minimize local variables
  7. Declare local variables in the inner most scope
  8. Reduce the number of parameters
  9. Use references for parameter passing and return value for types bigger than 4 bytes
  10. Don’t define a return value if not used
  11. Consider locality of reference for code and data
  12. Locality of reference in multi-dimensional arrays
  13. Prefer int over char and short
  14. Define lightweight constructors
  15. Prefer initialization over assignment
  16. Use constructor initialization lists
  17. Do not declare “just in case” virtual functions
  18. In-line 1 to 3 line functions
  19. Avoid cascaded function calls
  20. Prefer preincrement over postincrement
  21. Define move constructors in C++11
  22. Use hardware accelerators and SIMD hardware
  23. Use profile guided optimization

Leave a comment

GPU Based Parallel Computing with C++ AMP

C++ AMP lets you write C++ code that can directly target the GPU on the machine. Imagine being able to mix application code and signal processing code in a single program. The C++ AMP compiler takes care:

  1. Compiling the GPU code and loading it on the GPU
  2. Passing the data to from the application to the GPU
  3. Triggering the GPU computation
  4. Getting the results from the GPU and passing them back to the application.
The GPU code could perform performance intensive signal processing like FFT, turbo decoding and matrix multiplication.