Runtime of an process?

I an trying to determine the runtime of an task.
The taks/function is recursive, and having a hard time to define a timer which are able calculate the runtime..
Any suggestion?
You need to find out execution time of some code?

What problem do you have with calculating time? What don't you like in following pseudocode:

1
2
3
4
start = current time
Run your function
end = current time
duration = end - start
The idea was to implement it in the function, since i don't want want to include the the time it take to cout the return value.

But how do i get the current time?
i don't want want to include the the time it take to cout the return value.
1
2
3
4
5
start = current time
result = Run your function
end = current time
duration = end - start
cout result
If your function does output in addition to calculations, you are violating Single responsibility principle:
http://en.wikipedia.org/wiki/Single_responsibility_principle
http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29

But how do i get the current time?
http://en.cppreference.com/w/cpp/chrono
Last edited on
Topic archived. No new replies allowed.