diff options
| author | Christian Heimes <christian@cheimes.de> | 2008-02-04 18:00:12 (GMT) |
|---|---|---|
| committer | Christian Heimes <christian@cheimes.de> | 2008-02-04 18:00:12 (GMT) |
| commit | 422051a3675271e179995ad4a0f056ff94395d55 (patch) | |
| tree | 3316e9503901082cc4beefbf169d8191c9838190 /Lib/test/test_sys.py | |
| parent | a26cf9b7609fc1c08fd1a69ddf5e44dc98a70dce (diff) | |
| download | cpython-422051a3675271e179995ad4a0f056ff94395d55.zip cpython-422051a3675271e179995ad4a0f056ff94395d55.tar.gz cpython-422051a3675271e179995ad4a0f056ff94395d55.tar.bz2 | |
Patch #1953
I implemented the function sys._compact_freelists() and C API functions PyInt_/PyFloat_CompactFreeList() to compact the pre-allocated blocks of ints and floats. They allow the user to reduce the memory usage of a Python process that deals with lots of numbers.
The patch also renames sys._cleartypecache to sys._clear_type_cache
Diffstat (limited to 'Lib/test/test_sys.py')
| -rw-r--r-- | Lib/test/test_sys.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index aafbfa3..a01ea3e 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -363,6 +363,24 @@ class SysModuleTest(unittest.TestCase): self.assertEqual(type(getattr(sys.flags, attr)), int, attr) self.assert_(repr(sys.flags)) + def test_clear_type_cache(self): + sys._clear_type_cache() + + def test_compact_freelists(self): + sys._compact_freelists() + r = sys._compact_freelists() + # freed blocks shouldn't change + self.assertEqual(r[0][2], 0) + self.assertEqual(r[1][2], 0) + # fill freelists + ints = list(range(12000)) + floats = [float(i) for i in ints] + del ints + del floats + # should free more than 200 blocks each + r = sys._compact_freelists() + self.assert_(r[0][2] > 200, r[0][2]) + self.assert_(r[1][2] > 200, r[1][2]) def test_main(): test.test_support.run_unittest(SysModuleTest) |
