I want to iterate over a vector by index, then I:
for(size_t i=0;i<v.size();++i) {...}
I know that using an iterator to visit is more efficient, but I just want to discuss the compiler optimization at a technical point.
My question is: "v.size ()" is executed only once or several times?
Or the compiler will help me decide whether to calculate the size once enough or to call it several times using any optimization strategy, so I don't need:
size_t s=v.size() for(size_t i=0;i<s;++i)
to make the code more efficient?
My question is that this "v.size ()" is executed only once or several times?
, , , , .
, size() , .
size()
, v , , , . , ( , ) , , - , , .
v
, , , , 1 2 , . size() is O(1), , - . .
O(1)
Source: https://habr.com/ru/post/1662713/More articles:Installing dependencies for pip-only package via cond - pipReact Native on Android hangs after debugging for a while - react-nativeThe css: not () selector does not work - cssGroupByKey and create lists of pyspark sql dataframe values - group-bySQL CONSTRAINT another name - sql-serverКак нажать на github wiki без имени пользователя и пароля? - githubДолжны ли модули node.js экспортировать именованные функции или объекты? - javascriptThe sum of all data other than the sum of the individual data sets - sqlHow to set shell commands in Atom to enable atom command? - shellSelect using bootstrap3 entry-group entry height - selectize.jsAll Articles