Rev 3914: max() shows up under lsprof as more expensive than creating an object. in http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

John Arbash Meinel john at arbash-meinel.com
Thu Mar 26 20:19:49 GMT 2009


At http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

------------------------------------------------------------
revno: 3914
revision-id: john at arbash-meinel.com-20090326201840-ddb2uqof335ysvnu
parent: john at arbash-meinel.com-20090326195952-w0qea66iw597ipza
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: brisbane-core
timestamp: Thu 2009-03-26 15:18:40 -0500
message:
  max() shows up under lsprof as more expensive than creating an object.
  timeit also says if x < y is faster than y = max(x, y).
  Small win, but I'll take it.
-------------- next part --------------
=== modified file 'bzrlib/groupcompress.py'
--- a/bzrlib/groupcompress.py	2009-03-24 21:05:00 +0000
+++ b/bzrlib/groupcompress.py	2009-03-26 20:18:40 +0000
@@ -538,7 +538,11 @@
         # Note that this creates a reference cycle....
         factory = _LazyGroupCompressFactory(key, parents, self,
             start, end, first=first)
-        self._last_byte = max(end, self._last_byte)
+        # max() works here, but as a function call, doing a compare seems to be
+        # significantly faster, timeit says 250ms for max() and 100ms for the
+        # comparison
+        if end > self._last_byte:
+            self._last_byte = end
         self._factories.append(factory)
 
     def get_record_stream(self):



More information about the bazaar-commits mailing list