views:

111

answers:

4

hi,

I am working with an application in Linux. It supports both static and dynamic (.so) versions

From the performance standpoint, which version should a user use? The application performs computational tasks that require several hours of CPU time.

Any other advantage of using one lib over the other?

Thanks

+1  A: 

Normally you'd use the dynamic lib to reduce the size of the binary. No penalty at runtime except for the startup of the application which probably doesn't matter.

Dynamic librarys have another advantage: They allow you to change functions (i.e. to apply a bugfix) without having to recompile all programs using this function.
dbemerlin
A: 

Usually statically bound libraries are faster as they do not have the overhead of locating and loading of the library, but: for a multi-hour program the performance difference should be too small to notice.

Anyways, the only way to be really sure is: Benchmark it yourself.

dbemerlin
+1  A: 

From a performance standpoint, the differences are minimal unless the dynamic library would be loaded and unloaded often.

The only difference is that a dynamic library is loaded when needed instead of being built into (and thus ever present, sans load time) your executable.

The dynamic library can also be reused by several executables. This is the main reason I've used dynamic libraries in the past.

antik
A: 

From pure performance point of view:

Shared Objects are compiled as PIC (position independent code) that theoretically may be slightly less efficient then normal code on some architectures (including x86).

However, I don't think this would make any real difference.

From any other points

Use shared object, it has too many advantages over static library that it is just better alternative.

Artyom