mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merged revisions 70546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70546 | antoine.pitrou | 2009-03-23 19:41:45 +0100 (lun., 23 mars 2009) | 9 lines Issue #4688: Add a heuristic so that tuples and dicts containing only untrackable objects are not tracked by the garbage collector. This can reduce the size of collections and therefore the garbage collection overhead on long-running programs, depending on their particular use of datatypes. (trivia: this makes the "binary_trees" benchmark from the Computer Language Shootout 40% faster) ........
This commit is contained in:
parent
17e4fddb57
commit
3a652b1d0a
11 changed files with 397 additions and 2 deletions
|
@ -415,6 +415,33 @@ class GCTests(unittest.TestCase):
|
|||
|
||||
self.assertEqual(gc.get_referents(1, 'a', 4j), [])
|
||||
|
||||
def test_is_tracked(self):
|
||||
# Atomic built-in types are not tracked, user-defined objects and
|
||||
# mutable containers are.
|
||||
# NOTE: types with special optimizations (e.g. tuple) have tests
|
||||
# in their own test files instead.
|
||||
self.assertFalse(gc.is_tracked(None))
|
||||
self.assertFalse(gc.is_tracked(1))
|
||||
self.assertFalse(gc.is_tracked(1.0))
|
||||
self.assertFalse(gc.is_tracked(1.0 + 5.0j))
|
||||
self.assertFalse(gc.is_tracked(True))
|
||||
self.assertFalse(gc.is_tracked(False))
|
||||
self.assertFalse(gc.is_tracked(b"a"))
|
||||
self.assertFalse(gc.is_tracked("a"))
|
||||
self.assertFalse(gc.is_tracked(bytearray(b"a")))
|
||||
self.assertFalse(gc.is_tracked(type))
|
||||
self.assertFalse(gc.is_tracked(int))
|
||||
self.assertFalse(gc.is_tracked(object))
|
||||
self.assertFalse(gc.is_tracked(object()))
|
||||
|
||||
class UserClass:
|
||||
pass
|
||||
self.assertTrue(gc.is_tracked(gc))
|
||||
self.assertTrue(gc.is_tracked(UserClass))
|
||||
self.assertTrue(gc.is_tracked(UserClass()))
|
||||
self.assertTrue(gc.is_tracked([]))
|
||||
self.assertTrue(gc.is_tracked(set()))
|
||||
|
||||
def test_bug1055820b(self):
|
||||
# Corresponds to temp2b.py in the bug report.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue