This is my code:
// Start performance test clock
assert((start=clock())!=-1);
// Some reading and writing methods
// Get stop time
stop = clock();
cout << stop << endl;
// Calculate operation time
double result = (double)(stop-start)/CLOCKS_PER_SEC;
// Print result
cout << "--> Finished analysing in " << result << "s" << endl;
It works great when I debug my program, but when I run the release version,
stop receives a much smaller value than start, and result is a negative number.
Any ideas?
The assignment of
startshould not be in theassertstatement.assertis typically a no-op in release builds. So in the debug build, the statementstart=clock()would be executed, but in the release build, it would not. So it is possible (depending on earlier code and the declaration ofstart) that it is not initialized. It is typically desirable to avoid usingassertstatements that have side effects; it can lead to subtle differences/bugs between debug and release builds.It might be better to write it like this: