Changeset 99

Show
Ignore:
Timestamp:
07/21/06 11:57:12 (2 years ago)
Author:
mk
Message:

Added automatic timing for indices computation methods.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r98 r99  
    3636from util import mkdirs 
    3737from util import StdoutRedirector 
     38from util import time_function 
    3839from config import get_pkg_config 
    3940from codeparser import CodeParser 
     
    316317        if 'name' not in dict: 
    317318            setattr(cls, 'name', name) 
     319 
     320        if 'compute_with' in dict: 
     321            orig_compute_with = cls.compute_with 
     322 
     323            def _timed_compute_with(self, cheesecake): 
     324                (ret, self.time_taken) = time_function(lambda: orig_compute_with(self, cheesecake)) 
     325                self.cheesecake.log.debug("Index %s computed in %.2f seconds." % (self.name, self.time_taken)) 
     326                return ret 
     327 
     328            setattr(cls, 'compute_with', _timed_compute_with) 
    318329 
    319330    def __repr__(cls): 
  • branches/mk/cheesecake/util.py

    r98 r99  
    33import sys 
    44import tarfile 
     5import time 
    56import zipfile 
    67 
     
    177178        if not os.path.exists(path): 
    178179            os.mkdir(path) 
     180 
     181def time_function(function): 
     182    """Measure function execution time. 
     183 
     184    Return (return value, time taken) tuple. 
     185 
     186    >>> def fun(x): 
     187    ...     return x*2 
     188    >>> ret, time_taken = time_function(lambda: fun(5)) 
     189    >>> ret 
     190    10 
     191    """ 
     192    start = time.time() 
     193    ret = function() 
     194    end = time.time() 
     195    return ret, end-start