You can save about one-third of the time by removing the redundant Evaluate from your Table expression. Also, this result is entirely dependent on the MaxRecursion setting. If you remove this, or leave it in but increase its value, the plot takes longer than the table.
–
Verbeia♦Aug 28 '13 at 3:53

1

I used MaxRecursion -> 0 expecting that the Plot would evaluate exactly 1000 regularly spaced sample points, just like the Table. (Well, the Table actually evaluates 1001 points, but close enough.) Is that not true?
–
RahulAug 28 '13 at 4:01

I've read in few places that Table can be slow. Not sure why now. Yes, you are right, MaxRecursion -> 0 makes sure no more points are taken.
–
NasserAug 28 '13 at 4:06

2 times as fast as plot. I remembered my own questiondifference-of-speed-in-making-a-table on tables some time ago and this trick of making Table much faster. The point is : to keep it packed, need to have all limits be numerics ! When you had n in there, the upper limit was not. So the table was not packed. Now it is.

You could just also write

Table[Evaluate@f[x], {x, 0, 2. Pi, 2. Pi/1000}]

and get the speed advantage. The point again, all its limits needs to be numeric. See above question for more information and additional links on this subject.

Another example

Thanks! But for me it seems that the difference is not the presence of n or the addition of With. Doing First@Timing[Table[Evaluate@f[x], {x, 0, 2. Pi, 2. Pi/n}]] is fast while doing First@Timing[Table[Evaluate@f[x], {x, 0, 2 Pi, 2. Pi/n}]] as in my question is slow. (The difference is just one more decimal point.)
–
RahulAug 28 '13 at 5:18

@Rahul I'm using v7 so I can't check; is the output of RandomVariate a packed array of Real numbers?
–
Mr.Wizard♦Aug 28 '13 at 5:26

@Mr.Wizard: I'm just learning about packed arrays just now, so let me know if this is not how to check: PackedArrayQ is True and the Head of the first element is Real, so yes?
–
RahulAug 28 '13 at 5:34

@RahulNarain That's correct. I added an answer that you'll have to test yourself but it might be informative.
–
Mr.Wizard♦Aug 28 '13 at 5:39

Having read your linked question I see that With is necessary for multidimensional tables, which I will need in the future, so thanks for that too! Unfortunately I have already given you an upvote and a check mark, so all I can do now is leave an appreciative comment. :)
–
RahulAug 28 '13 at 7:14

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.