micro optimisation in for loop c++ -


Assume C ++ for loop as

  Integer should be allocated initially and after that, each phase should be increased. So it will not be fast enough to do something:  
  variables since f or (int i; i ++ <10;)   

Do not need to be reloaded in storage? When is this unstable ?

is making this small example code the same result for all the cases, whether the loop is optimized anyway or am I missing something?

  # include & lt; Iostream & gt; # Include & lt; Ctime & gt; Int main () {time_t start, ende; Unstable intimate dummy = 1; Const int rep = 1000000000; // method 1 start = time (0); For (int i = 0; i & lt; rep; i ++) dummy = 1; End = time (0); Std :: cout & lt; & Lt; "Method 1:" & lt; & Lt; Fifthme (End, Beginning) * 1000 & lt; & Lt; "MS" & lt; & Lt; Std :: endl; // method2 start = time (0); For (int i = 0; i ++> lie; representative;) dummy = 1; End = time (0); Std :: cout & lt; & Lt; "Method 2:" & lt; & Lt; Fifthme (End, Beginning) * 1000 & lt; & Lt; "MS" & lt; & Lt; Std :: endl; // method 3 start = time (0); For (Unstable int i = 0; i   

OS: Linux compiler: G ++ optimization: standart (no flag)

Compiler A lot is more efficient than you think. will not produce duplicate loads

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -