c++ - What is more efficient: vector.clear() or if(vector.empty()) clear();? -


as subject states.. version more efficient , why?

std::vector a; ..  a.clear(); 

or

std::vector a; .. if(!a.empty())   a.clear(); 

an empty vector valid vector. operation

a.clear(); 

is valid on empty vector.

test emptiness before clear unnecessary , time consuming, first 1 more efficient.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -