4 ms·
I 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
by fwsgonzo 7y ago
I 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.