Estimating the penalty of including Boost libraries
source link: https://mklimenko.github.io/english/2021/06/29/boost-inclusion-times/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Estimating the penalty of including Boost libraries
TL;DR; I’ve made a (yet another) simple repo and a table on its’ wiki to estimate the build penalty when including boost headers.
Boost libraries have a mixed reputation in the C++ community. There are a lot of exceptional quality libraries with algorithms and data structures missing in the standard library. One might even say, that the boost is kind of a playground to test something before it can get into the standard (smart pointers are one of the many examples). On the other hand, boost gets heavily criticized for overcomplication, custom build environment and a lot of cross-connections. Don’t forget the NIH syndrome, which once forced me to re-implement the static_vector
class.
C++ is (in)famous for it’s compilation times, especially for the template-heavy code. That got me thinking, how bad is the penalty for including the boost headers? So I’ve came up with a simple CMake script, which creates a trivial source file with a single #include
directive, repeated N times for all the main boost headers I could reach:
foreach(header ${HEADERS_TO_PROCESS})
string(REPLACE "." "-" filename_preliminary ${header})
string(REPLACE "/" "-" header_name ${filename_preliminary})
set(filename "${CMAKE_CURRENT_LIST_DIR}/${header_name}_main.cpp")
file(WRITE ${filename} "#include <${header}>\n int main() { return 0; }\n")
set(executable_name "Check${header_name}")
add_executable(${executable_name} ${filename})
target_compile_options(${executable_name} PUBLIC -ftime-trace)
target_link_libraries(${executable_name} pthread stdc++ stdc++fs)
endforeach()
Then I used the -ftime-trace
clang (9.0+, IIRC) switch to generate JSON report on the compilation times. I decided to settle for the whole .cpp
compilation time since it’s easier to drag it from the report.
Due to the fact, that neither Linux nor Windows are real-time operating systems, compilation times wouldn’t be constant and will have some distribution. To account for that, I ran the compilation process several times (10 to 20 looks fine to me) and averaged the results.
I wrote a simple program to read the clang reports, average the values and print them in a markdown-friendly way. I also decided that it would be interesting to estimate the relative slowdown to the plain int main()
source file. The resulting table looks something like this:
To make it more reproducible and trustworthy, I’ve added the Travis CI script to build, measure the time and auto-generate and upload to the wiki. As a rant, I’d like to say that I much prefer the GitLab way of CI, which is much more intuitive to me.
An interesting fact: I’ve conducted my first runs at my local PC (Ryzen 3700X, 32GB, WSL Ubuntu) and the bare int main()
took relatively the same time to compile (7.2 vs 8 ms), the time tripled for the heaviest boost files (2100 vs 6600 ms for the boost/geometry.hpp).
There’s a simple repo you may check out, the build dependencies are relatively simple (clang 9+ and boost, however, I encourage you to use ninja for speedup).
Recommend
-
85
-
136
Whenever we use helpers like io.Copy and ioutil.ReadAll like when we are reading from an http.Response body or uploading a file, we find that these methods block until the process is complete…
-
23
Contents: Getting to a real world case Collecting branch statistics Analyzing virtual calls and jump tables Subscribe to mymailing list to get more...
-
49
Awesome UI component library
-
55
README.md Dart A client-optimized language for fast apps on any platform Dart is: Optimized for UI:...
-
24
Estimating Uncertainty in Machine Learning Models — Part 3 Check out part 1 ( here )and part 2 (...
-
25
One Rep MaxA calculator for estimating your 1RM in weightlifting sportsOne Rep Max is a simple tool for estimating li...
-
13
Researchers are often interested in comparing statistical network models across groups. For example, Fritz and colleagues compared the relations between re...
-
7
Estimating the Fault Tolerant Cost of Classically Intractable Quantum ComputationsEstimating the Fault Tolerant Cost of Classically Intractable Quantum Computations - YouTube Live cha...
-
8
SIMONS: Estimating the cost of fault-tolerant classically intractable samplingTo enable screen reader support, press Ctrl+Alt+Z To learn about keyboard shortcuts, press Ctrl+slash
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK