I wonder about which method is actually faster than the rest.
For small programs (maybe I'm wrong), I thought 'using namespace std;' would be the slowest because it uses the entire standard library. Also, I thought that the fastest may be 'using std::'.
This finally brings me to the question:
Which is faster: 'using namespace std;', 'using std::', or 'std::'?
Would anyone please enlighten me about the efficiency of these commands? Or is it that they are all essentially the same?
I think std:: is the fastest than others. std::>using std::>using namespace std!
Because using namespace std search from the whole namespace std. But std::cout has not this problem!Others, using namespace and using std:: may generate variable conflict!
During execution (after the program is compiled --and when it really matters) it doesn't take any more time than any other variable access would.
During compilation, the object reference is stored in a lookup table the same as all other objects. The only difference is how many entries are listed in the lookup table --and I really doubt you'll be able to notice (let alone clock) any difference in compile time.
Duoas is right, however I would recommend "using namespace std;" as to avoid having to right "std::cout" or whatever for every command. Not only does it take less time to write with "using namespace std;" but it also makes the size of the file you are saving the code to a bit smaller, which some people like to have.
Woah. I can save keystrokes and save a few bytes in my source code? And all I have to do is embrace a practice that could produce conflicts to refer to symbols?
I'm convinced!
I personally don't like using it as every tutor I've had hates people using it. And myself I prefer using the std::cout anyway just so I know its from std::.
I've read code before as well where someone has done this: