Please see my comment to the question. Time complexity is not calculated, not in arithmetical sense of this word. I hope you understand that time complexity is not measured in seconds. Please see:
http://en.wikipedia.org/wiki/Time_complexity[
^],
http://en.wikipedia.org/wiki/Big_O_notation[
^].
For example, for
(int index = 0; index < length; ++index) { doSomething(index); }
the answer is O(n). How do we know that? Because, apparently, the number of calls to
doSomething
and, hence, time, is a linear function of
length
. When we can figure out and classify such function, we can find out a
complexity class.
It is also apparent that it's not always possible. After all, it is proven that it's possible to create an algorithm with unpredictable behavior, so finding time complexity may be a theoretically unresolvable problem, or the notion of time complexity may be not applicable at all.
—SA