-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
Description
Channel
C++Weekly
Topics
I would love to see some examples where code optimization optimizes "bad" code but not good code.
An example that I've observed with -O3
:
void print_int(std::ostream &out, int n) {
out << "The answer is " << n << ".\n";
}
void print_str(std::ostream &out, int n) {
out << "The answer is " << std::to_string(n) << ".\n";
}
I would expect the first function to be faster or equivalent to the second one which is not the case, at least on the devices I've tested. The second one is up to 5-10% faster depending the std version.
Do you know other examples like this?
Length
5-10 minutes