From: W. Trevor King Date: Sat, 21 Jul 2012 11:56:49 +0000 (-0400) Subject: Avoid expensive pformating in DynamicStructure.unpack_stream unless required. X-Git-Tag: v0.2~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ffb4b3eb3de75f53a92cbfe16473ab8c1461ea94;p=igor.git Avoid expensive pformating in DynamicStructure.unpack_stream unless required. If we're not going to be printing the formatted data in the log, don't bother calculating it. On my system, this speeds up the loading of polar-graphs-demo.pxp by a factor of 10. --- diff --git a/igor/struct.py b/igor/struct.py index fce93b5..ea8af34 100644 --- a/igor/struct.py +++ b/igor/struct.py @@ -717,7 +717,8 @@ class DynamicStructure (Structure): for f in self.fields: _LOG.debug('parsing {!r}.{} (count={}, item_count={})'.format( self, f, f.count, f.item_count)) - _LOG.debug('data:\n{}'.format(_pprint.pformat(data))) + if _LOG.level <= _logging.DEBUG: + _LOG.debug('data:\n{}'.format(_pprint.pformat(data))) if hasattr(f, 'pre_unpack'): _LOG.debug('pre-unpack {}'.format(f)) f.pre_unpack(parents=parents, data=data)