Skip to content
Advertisement

Dynamic library timing and CPU load analysis in linux

I am writing code with one dynamic library.

When I used dlopen/dlsym calls to access library functions, cpu load and execution is more as compared to linking library dynamically using -l and accessing function directly.

Can anyone help to understand why this is happening?

Advertisement

Answer

Static linking requires more time and i/o at link time because all the binding occurs during linking. The result is an executable file which needs no further processing for it to call the library code.

Dynamic loading requires more work at runtime. It has to look up the .so file, open it, and bind referenced addresses, all before the first call into it. What you are measuring is expected and normal.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement