Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Is 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.


I have a site for testing these things: 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.


Using 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.


To 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.


I'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 ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: