Are the “inline” keyword and “inlining” optimization separate concepts?

I wasn’t sure about your claim: Smaller functions are automatically “inlined” by optimizer irrespective of inline is mentioned or not… It’s quite clear that the user doesn’t have any control over function “inlining” with the use of keyword inline. I’ve heard that compilers are free to ignore your inline request, but I didn’t think they … Read more

Why/When you would not want to have Java 8 UseStringDeduplication enabled in JVM?

Cases where String de-duplication could be harmful include: There are lots of strings but a very low probability of duplicates: the time overhead of looking for duplicates and the space overhead of the de-duping data structure would not be repaid. There is a reasonable probability of duplicates, but most strings die in within a couple … Read more

Benefit of endless-loops without side effects in C++ being undefined behavior compared to C?

The reasons are optimizations only. If the compiler can assume that all loops without side effects terminate, it does not have to prove that. If the non-terminating loops were allowed, the compiler would be allowed to perform certain optimizations only if it could prove termination, that is impossible in general so it would turn into … Read more

How to change the learning rate of an optimizer at any given moment (no LR schedule)?

So the learning rate is stored in optim.param_groups[i][‘lr’]. optim.param_groups is a list of the different weight groups which can have different learning rates. Thus, simply doing: for g in optim.param_groups: g[‘lr’] = 0.001 will do the trick. **Alternatively**, as mentionned in the comments, if your learning rate only depends on the epoch number, you can … Read more

How do you compare float and double while accounting for precision loss?

Be extremely careful using any of the other suggestions. It all depends on context. I have spent a long time tracing bugs in a system that presumed a==b if |a-b|<epsilon. The underlying problems were: The implicit presumption in an algorithm that if a==b and b==c then a==c. Using the same epsilon for lines measured in … Read more

Do modern compilers optimize the x * 2 operation to x

Actually VS2008 optimizes this to x+x: 01391000 push ecx int x = 0; scanf(“%d”, &x); 01391001 lea eax,[esp] 01391004 push eax 01391005 push offset string “%d” (13920F4h) 0139100A mov dword ptr [esp+8],0 01391012 call dword ptr [__imp__scanf (13920A4h)] int y = x * 2; 01391018 mov ecx,dword ptr [esp+8] 0139101C lea edx,[ecx+ecx] In an x64 … Read more

What are your most common sql optimizations?

Reducing the amount of data that is returned, by only returning the fields required and only returning the rows required. This is the most common, as you do it for every query that returns data. With ENGINE=InnoDB, the above advice especially applies to avoiding unnecessary fetching of TEXT and BLOB columns since they may be … Read more

Are constant C expressions evaluated at compile time or at runtime?

Macros are simply textual substitution, so in your example writing TIMER_100_MS in a program is a fancy way of writing 32768 / 10. Therefore, the question is when the compiler would evaluate 32768 / 10, which is a constant integral expression. I don’t think the standard requires any particular behavior here (since run-time and compile-time … Read more