Блог пользователя cjquines

Автор cjquines, история, 10 лет назад, По-английски

This is based on the GNU C++11 compiler on Codeforces. Results inconclusive.

I will be omitting discussion of input and output, which is well-known.

  • No significant performance difference between ranged fors (26322469, 26322507) and iterating over elements (26316124)
  • No significant performance difference between assignment with tie (26322531) and regular assignment (26316124)
  • No significant performance difference between emplace, emplace_back (26316124) and push, push_back (26322556)

It is well known that auto is compile-time, so there will be no performance difference.

  • Проголосовать: нравится
  • +35
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

First of all, thanks for research. I really don't know why you have so much downvotes, but I can't do more than one upvote :(

Now about results and my thoughts:

  • compilers usually convert for(auto smth : container) into iterating with iterator. As far as I know, vector's iterator in GCC is actually a pointer. And when you are using operator [] for vectors, you actually just add some value to pointer. So difference is predictably indistinguishable.

  • tie was made for using with tuples. And it is just a syntactic sugar for easy converting tuple to set of variables. I think GCC converts it to regular assignment

  • emplace and emplace_back are good for structures and classes with no copy constructors inside. Or if class has easy creating and hard copying constructors.

Ofc, it's just IMHO.