6

In version, 10 StreamPlot seems to calculate many more points along each streamline than necessary, compared to version 7.

For example, from Mathematica documentation, the command

Block[{k = 0}, 
  StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, 
    EvaluationMonitor :> k++]; k]

gives 184 points in version 7 and 3592 points in version 10. I could not find an option that reduces the number of points calculated. For the complicated function I am trying to plot, it makes more than a factor of 10 difference in speed.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Mike
  • 81
  • 2
  • 2
    Have you seen StreamPoints? –  Apr 03 '15 at 06:30
  • 1
    StreamPoints controls the number of streamlines, not the number of points evaluated on each streamline. That is the question, is there an option that controls the number of points on each streamline – Mike Apr 06 '15 at 16:34
  • I have the same problem. StreamPlot is really too slow.. and cant be used in Manipulate...even for a simple function. – Nam Nguyen Mar 18 '16 at 15:31

1 Answers1

2

I do not experience much difference in performance of StreamPlot between versions 7 and 10.1 with the example given. In fact 10.1 is faster than 7.0 at 0.22 seconds versus 0.28 seconds. (Times for generation and rendering combined.)

However I can confirm the EvaluationMonitor steps reported, therefore I think this is a change to EvaluationMonitor rather than a performance issue. It does not report all points used in the plotting. For example we can greatly slow down StreamPlot by specifying a higher MaxRecursion value yet the EvaluationMonitor count remains unchanged:

Block[{k = 0}, 
  StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, 
    EvaluationMonitor :> k++,
    MaxRecursion -> 7];
  k
] // AbsoluteTiming

{6.61148, 3592}

Likewise MaxRecursion -> 0 plots somewhat faster than the default yet still returns a count of 3592. PerformanceGoal -> "Speed" does affect the count but also removes the stream arrows:

k = 0;

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},  
  EvaluationMonitor :> k++,
  PerformanceGoal -> "Speed"]

k

enter image description here

2382
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Thanks for looking into it, but to see real performance difference, one has to use more computationally complicated functions. Also, this example from the documentation actually plots the points being evaluated. I just added BesselJ to slow down the computation: Timing[ListPlot[ Reap[StreamPlot[{BesselJ[20, -1 - x^2 + y], BesselJ[20, 1 + x - y^2]}, {x, -3, 3}, {y, -3, 3}, EvaluationMonitor :> Sow[{x, y}]]][[-1, 1]]]] – Mike Jun 04 '15 at 02:19
  • @Mike I am still not seeing a large difference in performance. In version 7 StreamPlot[{BesselJ[20, -1 - x^2 + y], BesselJ[20, 1 + x - y^2]}, {x, -3, 3}, {y, -3, 3}, MaxRecursion -> 0] takes 1.75 seconds and in 10.1 it takes 2.36 seconds on my machine. This is significant but far smaller in magnitude than e.g. this ListPlot backslide. I guess what I am saying is that while I am not happy with it being slower it is way down the list of things that need attention in my mind. – Mr.Wizard Jun 04 '15 at 03:54
  • For the actual function I was trying to StreamPlot (too complicated to reproduce here) it was a full factor of 10 difference in speed. Looking at the plot of points that StreamPlot evaluates, it's clearly many more than necessary and more than a factor of 10 larger than in version 7. There doesn't seem to be any real way to control it since the "Speed" option does not reduce it significantly. So I think its a bug in the sampling algorithm. – Mike Jun 04 '15 at 05:32
  • @Mike I encourage you to attempt to find a smaller example that exhibits this larger difference in timing and update the question. An order of magnitude difference is very significant and deserves attention if nothing else. Perhaps there is a work-around too. – Mr.Wizard Jun 04 '15 at 13:45
  • 1
    Try Timing[StreamPlot[{Sum[If[n > 0, (-1 - x^2 + y), 0], {n, 1, 1000}], Sum[If[n > 0, (1 + x - y^2), 0], {n, 1, 1000}]}, {x, -3, 3}, {y, -3, 3}]]. Its a sum of 1000 identical terms. The If statement is to prevent Mathematica from compiling the expression, which gives funny scaling with n. This gives me in v. 7.0 a time of 1.6 sec and in v.10.0 a time of 18.3 sec. The number of points evaluated is identical to the example in documentation in each version, as expected. – Mike Jun 05 '15 at 03:00
  • @Mike It would be best if you edit that example into the question. In either v10.0.2 or v10.1.0 under Windows your example evaluates in under a second on my machine. In version 7.0.1 it takes about 1.4 seconds. You should note your OS and system configuration in the question. This may be a localized problem. – Mr.Wizard Jun 05 '15 at 14:59
  • Same problem for 10.4 :( A bug in StreamPlot – Nam Nguyen Mar 18 '16 at 15:32