3 ms·
Theoretically true, but colleagues of mine have done benchmarks showing MSVC has a slight overhead with exceptions enabled, even if none are thrown. Worth bench
by DerDangDerDang 7y ago
Theoretically true, but colleagues of mine have done benchmarks showing MSVC has a slight overhead with exceptions enabled, even if none are thrown. Worth benchmarking yourself if you need to be sure.
- monocasa 7y agoIs that recorded somewhere? The benchmarks I've done have been pretty all over the place and seem to be around jiggling the I$ alignment. Sometimes helps, sometimes hurts.
- fwsgonzo 7y agoI have a site for testing these things: https://droplet.fwsnet.net/ https://droplet.fwsnet.net/ I wrote some tests, not sure if they are perfect: #include <stdexcept> volatile int i = 1; __attribute__((noinline)) int test() { return i; } int main() { if (test() == 0) throw std::runtime_error(""); return 0; } ====> Instruction count: 612 Memory usage: 116 KB, top: 116 KB Compile time: 745326 micros Execution time: 149 micros Binary size: 98 KB The above is with exception, below is without: volatile int i = 1; __attribute__((noinline)) int test() { return i; } int main() { if (test() == 0) return -1; return 0; } ====> Instruction count: 251 Memory usage: 16 KB, top: 16 KB Compile time: 441626 micros Execution time: 53 micros Binary size: 3 KB Just remember to pick newlib as the target, as that is the thinnest, and the no-exceptions variant will be only 16kb.
- monocasa 7y agoUsing full process startup/shutdown for a microbenchmark is a bit specious. Also, what are your compile flags? godbolt shows a pretty big difference with -O2.
- fwsgonzo 7y agoTo monocasa, which I can't reply to: I agree completely, it really does run everything from start to finish. Sometimes that's what you want, and sometimes you don't. I could break on main as an option, and then start the benchmarking after main. It would include teardown, unless you call _exit() at the end of main. The compile flags are -O2, no linker GC.
- DerDangDerDang 7y agoI'm afraid not sorry. Though it probably wasn't a great benchmark. They were only investigating whether enabling exceptions has a cost if not thrown on MSVC. So a single example where there was a penalty was enough to cast doubt on exception usage. Enough that nobody felt like sticking their neck out to fight the cause, anyway ;)