I have often wondered this, is there a performance cost of splitting a string over multiple lines to increase readability when initially assigning a value to a string. I know that strings are immutable and therefore a new string needs to be created every time. Also, the performance cost is actually irrelevant thanks to today's really fas...
When does it make sense to use Loop fission/distribution if I am compiling for a single core processor?
...
In the spirit of the latest podcast where Joel mentioned he'd like some simple questions with possibly interesting answers ...
In the environments we have to programme in today we can't rely on the order of execution of our langauage statements. Is that true? Should we be concerned?
Will 30 GOTO 10 always go to 10?*
*I didn't use 20 ...
If this is not a real question then feel free to close ;)
...
This was an interview question. I said they were the same, but this was adjudged an incorrect response. From the assembler point of view, is there any imaginable difference? I have compiled two short C programs using default gcc optimization and -S to see the assembler output, and they are the same.
...
I understand you can use the inline keyword or just put a method in a class declaration ala short ctor or a getter method, but does the compiler make the final decision on when to inline my methods?
For instance:
inline void Foo::vLongBar()
{
//several function calls and lines of code
}
Will the compiler ignore my inline declarati...
General Question which may be of interest to others:
I ran into a, what I believe, C++-compiler optimization (Visual Studio 2005) problem with a switch statement. What I'd want to know is if there is any way to satisfy my curiosity and find out what the compiler is trying to but failing to do. Is there any log I can spend some time (pro...
I am aware that casting ints to floats (and vice versa) is fairly expensive. However, does the compiler automatically do it at compile time for constants in your code? For e.g. is there any difference between
float y = 123;
float x = 1 / y;
and
float y = 123.f;
float x = 1.f / y;
I see some code that does the latter, but I'm not su...
I work on a runtime system for an application domain that is very performance sensitive. We go to a lot of effort to maintain backward compatibility with older compiler versions, including avoiding more recently-implemented language constructs, and synthesizing them for the older versions.
However, I'm concerned that this effort does a ...
I have a workspace built using MS-Visual Studio 2005 with all C code.In that i see many functions which are not called but they are still compiled(they are not under any compile time macro to disable them from compiling).
I set following optimization settings for the MS-VS2005 project to remove that unused code:-
Optimization level - ...
In my language I can use a class variable in my method when the definition appears below the method. It can also call methods below my method and etc. There are no 'headers'. Take this C# example.
class A
{
public void callMethods() { print(); B b; b.notYetSeen();
public void print() { Console.Write("v = {0}", v); }
int v=9;...
How do modern optimizing compilers determine when to apply certain optimizations such as loop unrolling and code inlining?
Since both of these affect caching, naively inlining functions with less than X lines, or whatever other simple heuristic, is likely to generate worse performing code. So, how do modern compilers deal with this?
I'...
Are reordering and interleaving interchangeable terms when it comes to code compilation, optimization and execution?
...
While using modern C++ compilers (including MSVC, GCC, ICC), how can I say if it has:
parallelized the code
vectorized the loops (or used other specific processor instructions)
unrolled the loops
detected tail-recursion
performed RVO (return-value optimization)
or optimized in some other way
without diving into the assembler code the...
Hi
If you were constructing a compiler, what optimization at the AST level would be the nicest to have?
...
As the title says, what are the compiler, CLR or CPU optimizations to be aware of when working with threads and non-blocking synchronization?
I have read a little about the reordering of instructions to improve efficiency that could break things, and caching optimizations that will result in variables not being visible to other threads ...
So I was reading about the memory model that is part of the upcoming C++0x standard. However, I'm a bit confused about some of the restrictions for what the compiler is allowed to do, specifically about speculative loads and stores.
To start with, some of the relevant stuff:
Hans Boehm's pages about threads and the memory model in C++0...
I came across a bug in code that is only reproduced when the code is built with optimizations enabled. I've made a console app that replicates the logic for testing (code below). You'll see that when optimization is enabled 'value' becomes null after execution of this invalid logic:
if ((value == null || value == new string[0]) == fal...
The return value of a function is usually stored on the stack or in a register. But for a large structure, it has to be on the stack. How much copying has to happen in a real compiler for this code? Or is it optimized away?
For example:
struct Data {
unsigned values[256];
};
Data createData()
{
Data data;
// initialize d...
I was playing around today with some timing code and discovered that when asigning a string literal to std::string, that it was around 10% faster (with a short 12 char string, so likly even bigger difference for large strings) to do so with a literal of known length (using the sizeof operator) than not. (Only tested with the VC9 compiler...