[re-sending with also the 3rd patch file, sorry]

Hi,
  I am drawing some barcharts and scatter plot and the speed for rendering is 
awful once you have
100 000 of dots. I ran python profiler which lead me to .startswith() calls and 
some for loops
which append do a list repeatedly. This parts could be still sped up I think 
but a first attempt
is here:


UNPATCHED 1.2.1

real    23m17.764s
user    13m25.880s
sys     3m37.180s


PATCHED:

real    6m59.831s
user    5m18.000s
sys     1m40.360s



The patches are simple and because I see elsewhere in the code list expansions 
I do not see any
problems with backwards compatibility (new new python language features are 
required).

Hope this helps,
Martin

--- lib/matplotlib/artist.py.ori	2013-08-09 13:46:22.000000000 +0200
+++ lib/matplotlib/artist.py	2013-08-09 13:46:36.000000000 +0200
@@ -827,7 +827,7 @@
 
         """
         names = [name for name in dir(self.o) if
-                 (name.startswith('set_') or name.startswith('get_'))
+                 (name[:4] in ['set_', 'get_'])
                  and callable(getattr(self.o, name))]
         aliases = {}
         for name in names:

--- lib/matplotlib/axes.py.ori	2013-08-09 13:46:16.000000000 +0200
+++ lib/matplotlib/axes.py	2013-08-09 13:46:44.000000000 +0200
@@ -4424,7 +4424,7 @@
         for handle in self._get_legend_handles(legend_handler_map):
             label = handle.get_label()
             #if (label is not None and label != '' and not label.startswith('_')):
-            if label and not label.startswith('_'):
+            if label and label[0] != '_':
                 handles.append(handle)
                 labels.append(label)
 
@@ -8135,7 +8135,7 @@
 
         patches = []
 
-        if histtype.startswith('bar'):
+        if histtype[:3] == 'bar':
             totwidth = np.diff(bins)
 
             if rwidth is not None:
@@ -8183,7 +8183,7 @@
                     bottom[:] = m
                 boffset += dw
 
-        elif histtype.startswith('step'):
+        elif histtype[:4] == 'step':
             # these define the perimeter of the polygon
             x = np.zeros( 4*len(bins)-3, np.float )
             y = np.zeros( 4*len(bins)-3, np.float )

--- lib/matplotlib/figure.py.ori	2013-08-09 13:58:12.000000000 +0200
+++ lib/matplotlib/figure.py	2013-08-09 13:58:50.000000000 +0200
@@ -947,14 +947,11 @@
         # a list of (zorder, func_to_call, list_of_args)
         dsu = []
 
-        for a in self.patches:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.patches ]
 
-        for a in self.lines:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.lines ]
 
-        for a in self.artists:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.artists ]
 
         # override the renderer default if self.suppressComposite
         # is not None
@@ -990,15 +987,12 @@
             dsu.append((self.images[0].get_zorder(), self.images[0], draw_composite, []))
 
         # render the axes
-        for a in self.axes:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.axes ]
 
         # render the figure text
-        for a in self.texts:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.texts ]
 
-        for a in self.legends:
-            dsu.append( (a.get_zorder(), a, a.draw, [renderer]))
+        [ dsu.append( (x.get_zorder(), x, x.draw, [renderer])) for x in self.legends ]
 
         dsu = [row for row in dsu if not row[1].get_animated()]
         dsu.sort(key=itemgetter(0))
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to