[Mumps2Py:] [86] added some timing tests to file_open and parse_analyze_modules, lint removal otherwise.

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 86
Author:   pgallot
Date:     2008-02-06 03:20:50 +0000 (Wed, 06 Feb 2008)

Log Message:
-----------
added some timing tests to file_open and parse_analyze_modules, lint removal otherwise.

Modified Paths:
--------------
    trunk/mumps2py_ui.pyw


Modified: trunk/mumps2py_ui.pyw
===================================================================
--- trunk/mumps2py_ui.pyw	2008-02-06 03:17:13 UTC (rev 85)
+++ trunk/mumps2py_ui.pyw	2008-02-06 03:20:50 UTC (rev 86)
@@ -17,7 +17,7 @@
 ##    along with Mumps2Py.  If not, see <http://www.gnu.org/licenses/>.
 """ Implements a user interface for translating Mumps code to Python """
 
-import os, re, fileinput
+import os, re, fileinput, time
 from mumps2py.mumps_module import parse_for_routines
 from mumps2py.mumps2tok import parseMumps, ParseError
 from mumps2py.tok2python import translate
@@ -137,7 +137,7 @@
 """
         self.message(msg)
         
-    def display_before(self, filename, line_start = 1, line_end = -1):
+    def __display_before(self, filename, line_start = 1, line_end = -1):
         """populate the before window with the Mumps module's raw source code"""
         self.before_window.delete(0.0, END)
         for line in fileinput.input(filename):
@@ -149,13 +149,13 @@
             self.before_window.insert(END, line)
         fileinput.close()
 
-    def display_after(self, a_module, translation):
+    def __display_after(self, a_module, translation):
         """populate the after window with the translation of the Mumps module"""
         self.after_window.delete(0.0, END)
         for line in translation:
             self.after_window.insert(END, line)
 
-    def display_decomposed(self, a_module):
+    def __display_decomposed(self, a_module):
         """displays an intermediate decomposition of the Mumps code"""
         decomposed_window = self.info_window()
         for token in a_module.TokenList:
@@ -178,48 +178,17 @@
         if self.modules:
             for the_module in self.modules:
                 if the_module.mod_name == mod_name:
-                    self.display_before(the_module.input_file, \
-                                       the_module.start, \
-                                       the_module.end)
+                    self.__display_before(the_module.input_file, \
+                                          the_module.start, the_module.end)
                     try:
                         parseMumps(the_module)
                         translation = translate(the_module)
-                        self.display_after(the_module, translation)
+                        self.__display_after(the_module, translation)
                     except ParseError, err:
                         print err.error_msg()
-                    self.display_decomposed(the_module)
+                    self.__display_decomposed(the_module)
                     return
 
-    def parseuntilmodule(self, popup):
-        """analyze the tokens up until the module specified by popup"""
-        mod_name = self.entry_val.get()
-        popup.destroy()
-        toks = {}
-        entryrefs = {}
-        if self.modules:
-            for the_module in self.modules:
-                if the_module.mod_name == mod_name:
-                    break
-                
-                parseMumps(the_module)
-                for token in the_module.TokenList:
-                    token.count_subtokens(toks)
-                    token.extract_subtokens(entryrefs, (37, )) # 37 == ENTRYREF
-
-            analysis = [(v, k) for k, v in toks.items()]
-            analysis.sort(reverse = True)
-
-            analysis_window = self.info_window()
-            for count, toktype_key in analysis:
-                analysis_str = "%s: %d\n" % (toktype_key, count)
-                analysis_window.insert(END, analysis_str)
-
-            entryref_window = self.info_window()
-            print len(entryrefs[37]),"entryrefs."
-            for entryref in entryrefs[37]:
-                entryref_window.insert(END, str(entryref)+"***\n")
-
-
     def parse_all(self):
         """parse all the modules in a Mumps file"""
         if self.modules:
@@ -228,33 +197,52 @@
             if len(self.modules) == 1:
                 the_module = self.modules[0]
                 parseMumps(the_module)
-                self.display_decomposed(the_module)
+                self.__display_decomposed(the_module)
                 translation = translate(the_module)
-                self.display_after(the_module, translation)
+                self.__display_after(the_module, translation)
 
-    def parse_analyze_tokens(self):
-        """count the frequency of the different token types, sort and display"""
-        #import gc 
-        toks = {}
+    def parseuntilmodule(self, popup):
+        """analyze the tokens up until the module specified by popup"""
+        mod_name = self.entry_val.get()
+        popup.destroy()
+        mod_list = []
         if self.modules:
-            input_file = fileinput.input(self.modules[0].input_file)
             for the_module in self.modules:
-                print the_module.mod_name
-                if the_module.tokenlist_isempty():
-                    parseMumps(the_module, input_file)
-                for token in the_module.TokenList:
-                    token.count_subtokens(toks)
-                the_module.empty_tokenlist() # keep memory usage down
-                #gc.collect()
+                if the_module.mod_name == mod_name:
+                    break
+                mod_list.append(the_module)
+            self.parse_analyze_tokens(mod_list)                
 
-            fileinput.close()
+    def parse_analyze_tokens(self, mod_list = None):
+        """count the frequency of the different token types, sort and display"""
+        toks = {}
+        modcnt = 0
+        if mod_list:
+            modules_list = mod_list
+        else:
+            modules_list = self.modules
+        if modules_list:
+            try:
+                input_file = fileinput.input(modules_list[0].input_file)
+                tstart = time.time()
+                for modcnt, the_module in enumerate(modules_list):
+                    print the_module.mod_name
+                    if the_module.tokenlist_isempty():
+                        parseMumps(the_module, input_file)
+                    for token in the_module.TokenList:
+                        token.count_subtokens(toks)
+                    the_module.empty_tokenlist() # keep memory usage down
+            finally:
+                print time.time() - tstart, "seconds to parse %d routines" % \
+                      modcnt
+                fileinput.close()
+
             analysis = [(v, k) for k, v in toks.items()]
             analysis.sort(reverse = True)
 
             analysis_window = self.info_window()
             for count, toktype_key in analysis:
-                analysis_str = "%s: %d\n" % (toktype_key, count)
-                analysis_window.insert(END, analysis_str)
+                analysis_window.insert(END, "%s: %d\n" % (toktype_key, count))
 
     def file_close(self):
         """ clear out all the information for what was just open"""
@@ -277,9 +265,12 @@
 
         self.file_close()
             
+        tstart = time.time()
         self.modules = parse_for_routines(mumps_file, m2py_dir)
+        print time.time() - tstart,"seconds to load %d routines" \
+              % len(self.modules)
         if len(self.modules) == 1:
-            self.display_before(mumps_file)
+            self.__display_before(mumps_file)
                 
     def file_save(self):
         """ saves what is in the After window to a file."""


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/