Is it legal for a C++ optimizer to reorder calls to clock()?
The C++ Programming Language 4th edition, page 225 reads: A compiler may reorder code to improve performance as long as the result is identical to that of the simple order of execution . Some compilers, e.g. Visual C++ in release mode, will reorder this code: #include <time.h> ... auto t0 = clock(); auto r = veryLongComputation(); auto t1 = clock(); std::cout << r << " time: " << t1-t0 << endl; into this form: auto t0 = clock(); auto t1 = clock(); auto r = veryLongComputation(); std::cout << r << " time: " << t1-t0 << endl; which guarantees different result than original code (zero vs. greater