Created
April 10, 2020 10:27
-
-
Save dannas/29a2239d5d964d8c53413160aa9c0530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include <numeric> | |
| using namespace std; | |
| // Compare lowering of loops for -Og, -O2 and -O3 | |
| // https://godbolt.org/z/mNtLqi | |
| int f1(const vector<int> &v) { | |
| int sum = 0; | |
| for (int val : v) { | |
| sum += val; | |
| } | |
| return sum; | |
| } | |
| int f2(const vector<int> &v) { | |
| int sum = 0; | |
| for (auto p = begin(v); p != end(v); p++) { | |
| sum += *p; | |
| } | |
| return sum; | |
| } | |
| int f3(const vector<int> &v) { | |
| int sum = 0; | |
| for (size_t i = 0; i < v.size(); i++) { | |
| sum += v[i]; | |
| } | |
| return sum; | |
| } | |
| int f4(const vector<int> &v) { | |
| return accumulate(begin(v), end(v), 0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment