Hi All. In my C++ code I'm using the libc++ library and my question is about which construct is faster: for(auto line : lines) { ... } or for(auto it = lines.begin(); it != lines.end(); it++) { … } Thanks in advance for any answer. Luca.
Le 3 févr. 2012 à 16:31, Luca Ciciriello a écrit :> Hi All. > > In my C++ code I'm using the libc++ library and my question is about which construct is faster: > > for(auto line : lines) > { > ... > } > > or > > for(auto it = lines.begin(); it != lines.end(); it++) > { > … > } > > Thanks in advance for any answer.I agree with Alex Zavatone, just run a bench yourself and you will be fixed. You will get the answer faster than waiting that someone does it for you. -- Jean-Daniel
Hi Luca, Don't use 'auto' in LLVM code for now. We still support building via some host compilers that don't support it. -Jim On Feb 3, 2012, at 7:31 AM, Luca Ciciriello <luca_ciciriello at hotmail.com> wrote:> Hi All. > > In my C++ code I'm using the libc++ library and my question is about which construct is faster: > > for(auto line : lines) > { > ... > } > > or > > for(auto it = lines.begin(); it != lines.end(); it++) > { > … > } > > Thanks in advance for any answer. > > Luca. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Ok, thanks. Luca. On Feb 3, 2012, at 7:06 PM, Jim Grosbach wrote:> Hi Luca, > > Don't use 'auto' in LLVM code for now. We still support building via some host compilers that don't support it. > > -Jim > > On Feb 3, 2012, at 7:31 AM, Luca Ciciriello <luca_ciciriello at hotmail.com> wrote: > >> Hi All. >> >> In my C++ code I'm using the libc++ library and my question is about which construct is faster: >> >> for(auto line : lines) >> { >> ... >> } >> >> or >> >> for(auto it = lines.begin(); it != lines.end(); it++) >> { >> … >> } >> >> Thanks in advance for any answer. >> >> Luca. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
I don't think he's asking about code in the compiler itself. In any case, the foreach loop doesn't evaluate "end()" every iteration of the loop. Depending in what the container is, that could be worse. My advice is to use the foreach loop and file a bug if you find a case that is ever slower. -Chris On Feb 3, 2012, at 10:06 AM, Jim Grosbach <grosbach at apple.com> wrote:> Hi Luca, > > Don't use 'auto' in LLVM code for now. We still support building via some host compilers that don't support it. > > -Jim > > On Feb 3, 2012, at 7:31 AM, Luca Ciciriello <luca_ciciriello at hotmail.com> wrote: > >> Hi All. >> >> In my C++ code I'm using the libc++ library and my question is about which construct is faster: >> >> for(auto line : lines) >> { >> ... >> } >> >> or >> >> for(auto it = lines.begin(); it != lines.end(); it++) >> { >> … >> } >> >> Thanks in advance for any answer. >> >> Luca. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev