In this example I used appendTo.
f[x_] := x + 1;
data = {};
For[x = 1, x <= 10, x++,
f[x];
spec = AppendTo[data, {x, f[x]}]] // Timing // First
Out[37]= 0.000054
ListPlot[spec]
In this example I used appendTo.
f[x_] := x + 1;
data = {};
For[x = 1, x <= 10, x++,
f[x];
spec = AppendTo[data, {x, f[x]}]] // Timing // First
Out[37]= 0.000054
ListPlot[spec]
Try
Reap[For[x = 1, x <= 10, x++, f[x];
Sow[{x, f[x]}]
]][[2, 1]] // AbsoluteTiming
(*0.0000701*)
but it seems to be slower than your vewrsion.
Use Table for a significant faster version:
Table[{x, f[x]}, {x, 1, 10}]; // AbsoluteTiming
(*{0.0000199, Null}*)
For. It just doesn't exist.
– Sjoerd Smit
May 07 '20 at 13:52