0
$\begingroup$

I haven't been able to find anything to specifically answer my question:

When using Table[], I find that, for a program I am working on (I would post the code but there is a lot), when I set the length of the table to 100, it takes about 5 seconds to evaluate. However, when I set the table length to 1000, it takes well over 50 seconds to evaluate.

So it is obviously not a linear function, relating to the speed of table and the number of iterations. Why is this? Would it be related to RAM?

Thanks!

$\endgroup$
  • 2
    $\begingroup$ Is Table printing out its result in your notebook? (ie, do you have a ; at the end of your Table? If the output data is large, the frontend often slows down significantly. Otherwise, it would be great if you could try to reproduce this problem with some smaller code and post it here. $\endgroup$ – Carl Lange Sep 16 '18 at 0:28
  • $\begingroup$ Timing results depend strongly upon the function being iterated, especially if one needs to access different levels of memory (L1 cache, L2 cache, ...). Few, if any, iterative functions that employ memory are truly linear at sufficiently large $n$. $\endgroup$ – David G. Stork Sep 16 '18 at 0:30
  • 1
    $\begingroup$ There is no way to tell whether your code is linear or exponential without seeing the code. And even with the code, I'm not sure what your question is. Sure, some algorithms grow linearly, some grow exponentially, some grow slower, some grow faster. Table itself is essentially instantaneous; it is not this command what's causing the delay. $\endgroup$ – AccidentalFourierTransform Sep 16 '18 at 0:30
  • $\begingroup$ How to determine that it is not a linear relation, given only two data points? $\endgroup$ – Αλέξανδρος Ζεγγ Sep 16 '18 at 2:40
  • $\begingroup$ I will try and produce similar code and see if I can get similar results. In all honesty, the reason I left out the code was just to see if there is some general answer to this question, not necessarily because I need it to go faster. $\endgroup$ – Jmeeks29ig Sep 16 '18 at 3:07
2
$\begingroup$

After working on the problem for a little longer, I found out that it was foolish for me to assume that it was Table[] that was slowing down exponentially. What it actually was, was that one of the functions I was calling, that used random generators for part of it, sometimes ran very quickly, and, other times, ran very slowly. This is similar to what was said in the comments.

Using the function TimeConstrained[] to abort from the random functions when they became too time consuming, I was able to see that Table[] does not slow down very perceptibly between either 100 or 1000 iterations.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.