This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients docs@python, eric.araujo, ezio.melotti, pitrou, poq, rhettinger, terry.reedy
Date 2011-05-28.19:42:08
SpamBayes Score 7.2164497e-16
Marked as misclassified No
Message-id <1306611729.68.0.107395742186.issue12134@psf.upfronthosting.co.za>
In-reply-to
Content
From just reading the docs, it appears that json.dump(obj,fp) == fp.write(json.dumps(obj)) and it is easy to wonder why .dump even exists, as it seems a trivial abbreviation (and why not .dump and .dumpf instead). Since, '_one_shot' and 'c_make_encoder' are not mentioned in the doc, there is no hint from these either. So I think a doc addition is needed.

The benchmark is not completely fair as the .dumps timing omits the write call. For the benchmark, that would be trivial. But in real use on multitasking systems with slow (compared to cpu speed) output channels, the write time might dominate.  I can even imagine .dump sometimes winning by getting chunks into a socket buffer and possibly out on the wire, almost immediately, instead of waiting to compute the entire output, possibly interrupted by task swaps. So I presume *this* is at least part of the reason for the incremental .dump.

I changed 'pass' to 'print(bug)' in class writable and verified that .dump is *very* incremental. Even '[' and ']' are separate outputs.

DOC suggestion: (limited to CPython since spec does not prohibit naive implementation of .dump given above) After current .dumps line, add

"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."
History
Date User Action Args
2011-05-28 19:42:09terry.reedysetrecipients: + terry.reedy, rhettinger, pitrou, ezio.melotti, eric.araujo, docs@python, poq
2011-05-28 19:42:09terry.reedysetmessageid: <1306611729.68.0.107395742186.issue12134@psf.upfronthosting.co.za>
2011-05-28 19:42:09terry.reedylinkissue12134 messages
2011-05-28 19:42:08terry.reedycreate