[Rivet-svn] r3587 - in trunk: . pyext

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Feb 28 14:07:16 GMT 2012


Author: hoeth
Date: Tue Feb 28 14:07:15 2012
New Revision: 3587

Log:
lighthisto.py: Caching for re.compile(). In my case this reduced the calls to
re.compile by a factor of ~150, speeding up flat2aida and aida2flat by a factor
of 20-30.

Modified:
   trunk/ChangeLog
   trunk/pyext/lighthisto.py

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Mon Feb 27 13:23:33 2012	(r3586)
+++ trunk/ChangeLog	Tue Feb 28 14:07:15 2012	(r3587)
@@ -1,3 +1,8 @@
+2012-02-28  Hendrik Hoeth <hendrik.hoeth at cern.ch>
+
+	* lighthisto.py: Caching for re.compile(). This speeds up aida2flat
+	ant flat2aida by more than an order of magnitude.
+
 2012-02-27  Andy Buckley  <andy.buckley at cern.ch>
 
 	* doc/mk-analysis-html: Adding more LaTeX/text -> HTML conversion

Modified: trunk/pyext/lighthisto.py
==============================================================================
--- trunk/pyext/lighthisto.py	Mon Feb 27 13:23:33 2012	(r3586)
+++ trunk/pyext/lighthisto.py	Tue Feb 28 14:07:15 2012	(r3587)
@@ -553,6 +553,7 @@
     pat_comment = re.compile('^#|^\s*$')
     pat_property = re.compile('^(\w+?)=(.*)$')
     pat_path_property  = re.compile('^(\S+?)::(\w+?)=(.*)$')
+    pat_paths = {}
 
     def __init__(self, plotpaths=None, addfiles=[]):
         """
@@ -633,7 +634,9 @@
                 if m:
                     tag, pathpat = m.group(1,2)
                     # pathpat could be a regex
-                    if tag == section and re.match(pathpat,hpath):
+                    if not self.pat_paths.has_key(pathpat):
+                        self.pat_paths[pathpat] = re.compile(pathpat)
+                    if tag == section and self.pat_paths[pathpat].match(hpath):
                         startreading = True
                         if section in ['SPECIAL']:
                             ret[section] = ''


More information about the Rivet-svn mailing list