# CPU time in iteration process

Let $$Tx=\frac{x}{2}$$ for all $$x\in[0,1]$$. Let $$x_{0}\in[0,1]$$ and set an iterative sequence $$\{x_{n}\}$$ by the method $$x_{n+1}=Tx_{n}$$. Now if $$x_{0}=0.8$$, then I get a convergent sequence towards the unique fixed point of $$T$$ as follows. But I need the CPU time in this case. How I set the CPU time or where I can check the CPU time for method.

T[x_] := T[x] = (x/2);
x[0] = 0.9;
x[n_] := x[n] = T[x[n - 1]];
NumberForm[{Table[x[i], {i, 0, 6}]}, 9]
{{0.9, 0.45, 0.225, 0.1125, 0.05625, 0.028125, 0.0140625, 0.00703125}}


How I set the CPU time or where I can check the CPU time for method

One way is to use TimeUsed[] and at the end subtract the times. Something like this

t0 = TimeUsed[];
T[x_] := T[x] = (x/2);
x[0] = 0.9;
x[n_] := x[n] = T[x[n - 1]];
Quiet@NumberForm[{Table[x[i], {i, 0, 100000}]}, 9];
Print["time used in CPU seconds is ", TimeUsed[] - t0]


Which gives

If you want clock time used (not CPU time), then you can use AbsoluteTiming but note this measures time elapsed, not CPU time. This are not the same. So it depends on what you want.

• Thanks dear @Nasser thanks for you helpful answer. However with every click, the value changes for CPU time. For example, 0.25, 0.281 etc in my CPU Commented Feb 28, 2023 at 18:33
• @JunaidAhmad you need to reset t0 (initial time) each time where you want to measure the CPU time used. Commented Feb 28, 2023 at 18:35