Prototype 1 Prototype 2

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; }
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> int main() { int size; int i; std::cin >> size; std::vector<int> array(size); for (i = 0; i < size; i++) { array[i] = rand(); } std::sort(array.begin(), array.end()); for (i = 0; i < size; i++) { std::cout << array[i]; std::cout << std::endl; } return 0; }

Hover the green text in the other frame.

Register Allocation: size is stored in a register all along its live range.

Live Range: i is used independently in two loops, it should be declared locally in each of them.

Register Allocation: i is stored in a register all along its live range.

Static Profiling: The variable is expected to range from 0 upwards.

Input function: The integer properties have been specified, the input function is optimal.

Static Profiling: size is not guaranteed to be non-negative, it could be declared unsigned.

Containers Storage: array is stored on the stack thanks to its final size being specified at construction.

Vectorization: rand() will be vectorized with its containing loop.

Algorithms: The implementation for sort was chosen to match the properties of the array.

Iostream: endl is a non-trivial function, it could be replaced by '\n' and flush() be called after the loop.