Optimization of C/C++ Program

 

                               Optimization of C/C++ Program

 gcc -O3 <c-filename.c>

#pragma GCC optimize("O3") 
or

#pragma GCC optimize("Ofast")   
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("omit-frame-pointer")

inline functions for small functions

Always use Assembly based library instead of writing algo from scratch or Open-source library Example:- For AES Algo we have AES Assembly instructions that is the best optimization
https://en.wikipedia.org/wiki/AES_instruction_set

use your own designed library function or else use C++ library functions i.e. std::memcpy as they are better than C counter part.

process affinity/core binding

zero-copy mechanism to pass buffer

used Shared Memory for IPC

declare register variables to limited but frequently used variables

need Profiler(gprof & valgrind)

gcc -pg -o whatever.o whatever.c

./whatever

gprof whatever gmon.out

valgrind --tool=callgrind ./(Your binary)

https://codeforces.com/blog/entry/66279

https://stackoverflow.com/questions/375913/how-can-i-profile-c-code-running-on-linux

https://medium.com/@aka.rider/how-to-optimize-c-and-c-code-in-2018-bd4f90a72c2b

https://stackoverflow.com/questions/653980/list-of-common-c-optimization-techniques


https://devblogs.microsoft.com/cppblog/optimizing-c-code/





Comments

Popular posts from this blog

OS Books

How to get symbol table in gcc/g++ ?

Memory corruption issue