def __call__(self, nodes, num_threads=1): """ Called by Translator object, this executes the steps listed in the class description. """ total = time.time() self.assertInitialized() nodes = nodes or self.translator.content source_nodes = [n for n in nodes if isinstance(n, pages.Source)] other_nodes = [n for n in nodes if not isinstance(n, pages.Source)] LOG.info('Executing preExecute methods...') t = time.time() self._executeExtensionFunction('preExecute', None, args=(self.translator.content,)) LOG.info('Finished preExecute methods [%s sec.]', time.time() - t) t = time.time() LOG.info('Translating using %s threads...', num_threads) if self.get('profile', False): mooseutils.run_profile(self.execute, source_nodes, num_threads) else: self.execute(source_nodes, num_threads) LOG.info('Translating complete [%s sec.]', time.time() - t) # Indexing/copying LOG.info('Finalizing content...') t = self.finalize(other_nodes, num_threads) LOG.info('Finalizing Finished [%s sec.]', t) LOG.info('Executing postExecute methods...') t = time.time() self._executeExtensionFunction('postExecute', None, args=(self.translator.content,)) LOG.info('Finished postExecute methods [%s sec.]', time.time() - t) LOG.info('Total Time [%s sec.]', time.time() - total)
def _run(self, nodes, target): """Run and optionally profile a function""" if self['profile']: mooseutils.run_profile(target, nodes) else: target(nodes)
def _run(self, nodes, target, prefix): """Run and optionally profile a function""" t = time.time() LOG.info('%s...', prefix) if self.get('profile', False): mooseutils.run_profile(target, nodes) else: target(nodes) LOG.info('Finished %s [%s sec.]', prefix, time.time() - t)
else: return self.get('content') def copy(self, _parent=None): """Copy the String. These shouldn't have children, so don't worry about them.""" return String(_parent, **self.attributes) if __name__ == '__main__': import mooseutils class Node(object): def __init__(self, parent, name, **kwargs): self.children = list() self.attributes = dict() self.attributes.update(kwargs) if parent is not None: parent.children.append(self) def createTree(N, cls): body = cls(None, 'body') for i in range(N): div0 = cls(body, 'div') for j in range(N): div1 = cls(div0, 'div') for k in range(N): p = cls(div1, 'p', string='STUFF') mooseutils.run_profile(createTree, 100, Tag) mooseutils.run_profile(createTree, 100, Node)