c - Strange compiler speed optimization results - IAR compiler -


i'm experiencing strange issue when try compile 2 source files contain important computing algorithms need highly optimized speed.

initially, have 2 source files, let's call them a.c , b.c, each containing multiple functions call each other (functions file may call functions other file). compile both files full speed optimizations , when run main algorithm in application, takes 900 ms run.

then notice functions 2 files mixed logical point of view, move functions a.c b.c; let's call new files a2.c , b2.c. update 2 headers a.h , b.h moving corresponding declarations.

moving function definitions 1 file other modification make!

the strange result after compile 2 files again same optimizations, algorithm takes 1000 ms run.

what going on here?

what suspect happens: when functions f calls function g, being in same file allows compiler replace actual function calls inline code optimization. no longer possible when definitions not compiled @ same time.

  1. am correct in assumption?
  2. aside regrouping function definitions before, there can obtain same optimization before? researched , seems it's not possible compile 2 source files simultaneously single object file. order of compilation matter?

as whether assumption correct, best way tell examine assembler output, such using gcc -s or gcc -save-temps. that definitive way see compiler has done.

as compiling 2 c source files single object file, that's certainly doable. create ab.c follows:

#include "a.c" #include "b.c" 

and compile that.

barring things should kept separate (such static items may exist in both c files), should work (or @ least work little modification).

however, remember optimisation mantra: measure, don't guess! you're giving fair bit of encapsulation combining them make sure benefits outweigh costs.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -