Benefits of ‘Optimize code’ option in Visual Studio build

You are the only person who can answer the “performance hit” question. Try it both ways, measure the performance, and see what happens. The hit could be enormous or it could be nonexistant; no one reading this knows whether “enormous” to you means one microsecond or twenty minutes. If you’re interested in what optimizations are … Read more

GCC removes a bounds check in the right operand of &&, but not in the left operand, why?

Accessing an array out of bounds is undefined behavior so the compiler can assume that it never happens in the LHS of the && expression. It is then jumping through hoops (optimizations) to notice that since ARRAY_LENGTH is the length of the array, the RHS condition must necessarily hold true (otherwise UB would ensue in … Read more

GCC: vectorization difference between two similar loops

In the first case: the code overwrites the same memory location a[i] in each iteration. This inherently sequentializes the loop as the loop iterations are not independent. (In reality, only the final iteration is actually needed. So the entire inner loop could be taken out.) In the second case: GCC recognizes the loop as a … Read more

Performance of resizing std::vector

The claim that unique_ptr performs as well as a raw pointer after optimization mostly applies only to the basic operations on a single pointer, such as creation, dereferencing, assignment of a single pointer and deletion. Those operations are defined simply enough that an optimizing compiler can usually make the required transformations such that the resulting … Read more

Disable compiler optimisation for a specific function or block of code (C#)

You can decorate a specific method (or a property getter/setter) with [MethodImpl(MethodImplOptions.NoOptimization)] and [MethodImpl(MethodImplOptions.NoInlining)], this will prevent the JITter from optimizing and inlining the method: [MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] private void MethodWhichShouldNotBeOptimized() { } However, there isn’t a way to apply this attribute to a block of code. Also NoOptimization attribute was added in .NET 3.5, … Read more

Do compilers take advantage of the indeterminate sequencing of function arguments?

It depends on the argument type, the called function’s calling convention, the archtecture and the compiler. On an x86, the Pascal calling convention evaluates arguments left to right whereas in the C calling convention (__cdecl) it is right to left. Most programs which run on multiple platforms do take into account the calling conventions to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)