diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-08-19 16:03:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-08-19 16:03:14 (GMT) |
commit | df7fc9dda7729d446d0a6ea48c4cea98ffa64cad (patch) | |
tree | 73c4d0997a9238e1cb3dd7acbb27ad46a127c305 /Lib/test/json_tests | |
parent | 9bb6dfe0a8a57c8919ff0855a4aa0b78f5ce8046 (diff) | |
download | cpython-df7fc9dda7729d446d0a6ea48c4cea98ffa64cad.zip cpython-df7fc9dda7729d446d0a6ea48c4cea98ffa64cad.tar.gz cpython-df7fc9dda7729d446d0a6ea48c4cea98ffa64cad.tar.bz2 |
Issue #12778: Reduce memory consumption when JSON-encoding a large container of many small objects.
Diffstat (limited to 'Lib/test/json_tests')
-rw-r--r-- | Lib/test/json_tests/test_dump.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/json_tests/test_dump.py b/Lib/test/json_tests/test_dump.py index 083c11f..f1c1b04 100644 --- a/Lib/test/json_tests/test_dump.py +++ b/Lib/test/json_tests/test_dump.py @@ -1,6 +1,7 @@ from io import StringIO from test.json_tests import PyTest, CTest +from test.support import precisionbigmemtest, _1G class TestDump: def test_dump(self): @@ -21,4 +22,20 @@ class TestDump: class TestPyDump(TestDump, PyTest): pass -class TestCDump(TestDump, CTest): pass + +class TestCDump(TestDump, CTest): + + # The size requirement here is hopefully over-estimated (actual + # memory consumption depending on implementation details, and also + # system memory management, since this may allocate a lot of + # small objects). + + @precisionbigmemtest(size=_1G, memuse=1) + def test_large_list(self, size): + N = int(30 * 1024 * 1024 * (size / _1G)) + l = [1] * N + encoded = self.dumps(l) + self.assertEqual(len(encoded), N * 3) + self.assertEqual(encoded[:1], "[") + self.assertEqual(encoded[-2:], "1]") + self.assertEqual(encoded[1:-2], "1, " * (N - 1)) |