I know I can find out the amount of time a function takes to run like this:
In:= function1[100] //Timing
Out:= {0.043334, Null}
How can I graph this over a set of 10 or 20 parameters (which are increasingly large), in order to get an idea of how the function scales?
Answer
This isn't the most exciting example but I hope it helps.
Use AbsoluteTiming
to time the function and use Table
to iterate over a set of values. We're simply going to time the Pause
function which just waits x
seconds, in this case x^2
. The values will be stored as list
. First
gives us the first element of the output of AbsoluteTiming
which is the time taken.
list = Table[First[AbsoluteTiming[Pause[x^2]]], {x, 0, 0.1, 0.01}];
Then we'll plot it with ListPlot
ListPlot[list]
Comments
Post a Comment