I've long wondered when writing my C++ CMake files which is faster for the compiler:
- Putting all my project's cpp files in a single shared
.so
library usingadd_library()
- Using multiple libraries, one for each class / logical component.
Internet searching has not turned up any relevant articles about this curiosity so I thought I'd run a very simple experiment. I made two version of my project - one with a single library and one with two libraries. I found that, over runs, the single library version was 25% faster when compiling from scratch, and 1% faster when compiling after modifying a single line in one of the files. Granted, my experiments were not very thorough.
This is surprising to me - I've always thought having multiple libraries would speed up compiling of small changes in just one of the libraries, because the compiler wouldn't have to touch other libraries that did not depend on it.
- Does anyone know a general performance rule about CMake libraries?
- Can anyone explain why I see this difference?
Thanks!
Update: I'm compiling on Ubuntu 14.04 with gcc 4.8.4