I wonder what is the performance difference between fill_n and a for-loop when initializing
an array?
Which one is better?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just tested these three codes (Compiled by GCC 4.7.2 with
-O3optimization):I added these two lines to all the codes, because I think without them the GCC optimizer will deceive me.
1.cpp
2.cpp
3.cpp
Measure times: