1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int size, i; cin >> size; vector<int> array(size); for (i = 0; i < size; i++) { array[i] = rand(); } sort(array.begin(), array.end()); for (i = 0; i < size; i++) { cout << array[i] << endl; } return 0; } |
Here is the original command-line output from the compiler:
$ cc test.c -o test test.c:10:14: info: ‘array’ being initialized once only, it will be stored on the stack since its final size is known at construction. test.c:10:14: note: See <Storage of standard containers>. test.c:12:14: info: ‘rand()’ being a linear congruential generator by default, it will be vectorized along with the containing loop. test.c:12:14: note: See <Vectorizable operations>. test.c:16:23: alert: ‘endl’ flushes the output along with inserting ‘\n’. Replacing it with ‘\n’ alone and calling ‘flush()’ after the containing loop would increase performance by 3%. test.c:16:23: note: See <Performance of iostream operations>.
array being initialized once only, it will be stored on the stack since its final size is known at construction.
rand() being a linear congruential generator by default, it will be vectorized along with the containing loop.
endl flushes the output along with inserting '\n'. Replacing it with '\n' alone and calling flush() after the containing loop would increase its performance by 3%.