Why do I have to turn on optimization in g++ for simple array access?
问题 I have written a simple Gaussian elimination algorithm using a std::vector of double s in C++ (gcc / Linux). Now I have seen that the runtime depends on the optimization level of the compiler (up to 5-times faster with -O3 ). I wrote a small test program and received similar results. The problem is not the allocation of the vector nor any resizing etc. It's the simple fact that the statement: v[i] = x + y / z; (or something like that) is much slower without optimization. I think the problem