Michael Bayer wrote:
> you need to forward the *actual test program* which you are running. i
> have tests for performance which generally show very minute speed
> differences between 0.2 and 0.3. The logging statements can be sped up
> by making them conditional and maybe removing some.
I've noticed that SA is doing a lot of string formatting in logging statements
like this:
log.debug('%s %s' % ('green', 'apples'))
log.debug("(" + self.abc + "|" + self.xyz + ") " + msg)
The logging package is designed to allow string formatting to be deferred until
the log statement is actually written to a log (so it only happens when logging
is enabled). Here's how you'd take advantage of that:
log.debug('%s %s', 'green', 'apples')
log.debug("(%s|%s) %s", self.abc, self.xyz, msg)
Also, you need to stop writing Perl in Python :) The mapper logging is quite
inefficient. Here's a quick example of how that could be improved:
class MapperLoggingExample(object):
def __init__(self):
# ...
if logging.is_debug_enabled(self.logger):
name = ["(", self.class_.__name__, "|"]
if self.entity_name is not None:
name.extend(["/", self.entity_name])
if self.local_table:
name.append(self.local_table.name)
else:
name.append(self.local_table)
if not self._is_primary_mapper():
name.append("|non-primary")
name.append(") %s")
logging_name = "".join(name)
self.log_fast = lambda msg: self.logger.debug(logging_name, msg)
else:
self.log_fast = lambda msg: None
def log_slow(self, msg):
self.logger.debug("(" + self.class_.__name__ + "|" + (self.entity_name
is not None and "/%s" % self.entity_name or "") + (self.local_table and
self.local_table.name or str(self.local_table)) + (not
self._is_primary_mapper() and "|non-primary" or "") + ") " + msg)
# usage example
m = MapperLoggingExample()
m.log_slow("test message")
m.log_fast("test message")
According to my tests, log_fast() is about 50 times faster than log_slow() when
logging is disabled, and marginally faster when logging is enabled.
~ Daniel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---