[docs] [issue12134] json.dump much slower than dumps

Antoine Pitrou report at bugs.python.org
Sun Jun 5 13:29:21 CEST 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

> "In CPython, json.dumps(o), by itself, is faster than json.dump(o,f),
> at the expense of using more space, because it creates the entire
> string at once, instead of incrementally writing each piece of o to f.
> However, f.write(json.dumps(o)) may not be faster."

Uh, talking about "CPython" is not very helpful here and only muddies
the waters IMO.
Something like "typical implementations of dump() will try to write the
result in small chunks and will therefore trade lower memory usage for
higher serialization time. If you have enough memory and care about
performance, consider using dumps() and write the result yourself with a
single write() call".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12134>
_______________________________________


More information about the docs mailing list