I am working with an appl开发者_StackOverflow中文版ication 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
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.
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.
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.
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.
精彩评论