So I have my program that does some stuff for a some period of time. I'm trying to output time taken at specific points of program (Starting with Time taken to execute program). The code I'm using to do that is as follows:
1 2 3 4 5
int main(int argc, char **argv) {
std::chrono::system_clock::time_point Started=std::chrono::system_clock::now();
//Long Stuff Here
std::cout << "Time taken " << std::chrono::duration_cast<std::chrono::duration<int>>(std::chrono::system_clock::now() - Started).count() << std::endl;
}
The problem is, that outputted number does not represent the time take to execute the program.
1 2 3 4 5 6 7 8 9
time ./obe
Time taken 923469
real 15m23.889s
user 57m10.496s
sys 0m13.969s
echo $((923469/60))
15391
I'm not really familiar with this c++11 feature - but after doing a quick lookup it seems like you're handing duration_cast a parameter of type time_point, whilst this: http://cplusplus.com/reference/std/chrono/duration_cast/ states that it should take a duration as an argument.
If that doesn't seem to be the cause of the problem, perhaps it's good to try and move the question to the "general C++ programming" section as this is not strictly beginner material.
@NwN
Hmm .. I think std::chrono::system_clock::now() - Started
returns a duration
It seems that the time is too big for time point (or duration ) to handle, as if I make the programm shorter, it works OK!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
time ./obe
Time taken 83.469
real 1m23.156s
user 5m20.042s
sys 0m1.240s
//Change length of operation
time ./obe
Time taken 211469
real 3m31.360s
user 13m22.248s
sys 0m3.286s