|
From: | Jens.Wulf |
Subject: | Slow plotting (redraw due to legend?) |
Date: | Thu, 10 Mar 2016 10:00:25 +0000 |
Hello, due to really slow plotting with newer versions I still use octave 3.2.3. I also tried 3.6.4, some 3.8.x versions and 4.0.0. Generally newer versions seem slower than older ones.
On linux it is two to four times faster than on windows (although the hardware is slower, but that’s something I encountered with other programs before).
When trying to create a simple example (see below) I found that the way the legend is created makes a huge difference with newer versions. I could not get better than three seconds
with 4.0.0 while 3.2.3 constantly achieves 0.13s no matter in which order those legend()-calls are made.
The code below creates a plot which is typical for my use case; I usually create about four of them in every step. Sometimes they contain more plots, which increases waiting time
from 10s (3.2.3) to about two minutes (4.0.0). ------------------------------------------------------------------------------------------ vLen = [11 11 11 11 11 11 11 20 1 42 42 42 42 42 2 2]; cTyp = {'-*' '-^' '-*' '-^' '-*' '-^' '-v' '-' '^' '-' '-' '-' '-' '-' '-' '-'}; vCol = [5 5 5 5 5 5 2 1 1 5 5 5 3 1 0 0]; vW = [2 2 2 2 2 2 2 4 2 4 4 4 4 4 1 1]; cLeg = cell(16,1); tic() if index(version(), '3.2') == 1 || false bProf = 0; else bProf = 1; profile on; end bAfter = true figure(1) newplot(); hold on; for n=1:length(vLen) vX = linspace(0,1,vLen(n))'; vY = rand(vLen(n),1); if bAfter plot(vX, vY(1:vLen(n)), [cTyp{n} num2str(vCol(n))], 'linewidth', vW(n)/2); else % dead slow on newer versions, just fine with 3.2.3: plot(vX, vY(1:vLen(n)), [cTyp{n} num2str(vCol(n)) ';foo ' num2str(n) ';'], 'linewidth', vW(n)/2); end cLeg{n} = ['foo ' num2str(n)]; end hold off if true if bAfter legend(cLeg, 'location', 'southeast'); else legend('location', 'southeast'); end if true legend('boxoff'); legend('left');
end end axis([-0.1 1.3 -0.1 1.1]); grid('on'); title('Title'); xlabel('xlabel'); ylabel('ylabel'); toc() if bProf profile off; data = ""> profshow(data,10); end ------------------------------------------------------------------------------------------ Profiler results give some information on what is happening (but not possible with 3.2.3). Without legend, octave 4.0.0 (absolute times are nonstandard because it is virus scanning
time now): # Function Attr Time (s) Time (%) Calls --------------------------------------------------------------- 103 __line__ 0.602 52.44 16 106 cellfun 0.296 25.78 31 107 __go_line__ 0.082 7.14 16 20 set 0.020 1.74 32 66 repmat 0.019 1.66 48 12 get 0.017 1.48 292 33 __go_axes_init__ 0.015 1.31 1 54 num2str 0.012 1.05 32 88 __plt__ 0.009 0.78 16 81 ostrsplit 0.007 0.61 32 With legend, but without calling legend(‘boxoff’) and legend(‘left’): # Function Attr Time (s) Time (%) Calls ---------------------------------------------------------- 92 __line__ 1.480 53.01 39 96 cellfun 0.722 25.86 54 20 set 0.188 6.73 111 97 __go_line__ 0.126 4.51 39 12 get 0.030 1.07 624 101 legend 0.023 0.82 1 41 num2str 0.020 0.72 32 121 __go_text__ 0.016 0.57 17 76 __plt__ 0.015 0.54 16 54 repmat 0.014 0.50 51 With legend as I like it: # Function Attr Time (s) Time (%) Calls ---------------------------------------------------------- 103 __line__ 2.395 53.27 62 106 cellfun 1.164 25.89 77 20 set 0.353 7.85 179 107 __go_line__ 0.176 3.91 62 111 legend 0.068 1.51 3 12 get 0.052 1.16 1092 128 __go_text__ 0.028 0.62 33 132 findobj 0.021 0.47 2 54 num2str 0.019 0.42 32 126 text 0.017 0.38 33 While 4.0.0 without legend is eight times slower than 3.2.3 (with or without legend), it seems that those legend()-calls cause redrawing which makes it even worse. I did not notice a difference with different graphics_toolkit()s. However, I don’t think fltk and qt are an option currently. Is there a way of changing the above code to speed up plotting with current versions or a chance that octave will get back to its previous performance? And yes, I really want the
legend without a surrounding box and with text left of linetype. Thanks for reading up to this point and best regards, Jens SEW-EURODRIVE GmbH & Co KG Kommanditgesellschaft, Sitz: Bruchsal, RG Mannheim HRA 230970 Komplementärin: SEW-EURODRIVE Verwaltungs-GmbH, Sitz: Bruchsal, RG Mannheim HRB 230207 Gesellschafter: Jürgen Blickle, Rainer Blickle Geschäftsführer: Jürgen Blickle (Vorsitzender), Udo Aull, Johann Soder, Dr. Jürgen Zanghellini |
[Prev in Thread] | Current Thread | [Next in Thread] |