[issue12134] json.dump much slower than dumps

poq report at bugs.python.org
Sat May 21 15:38:06 CEST 2011


New submission from poq <poq at gmx.com>:

import json, timeit
obj = [[1,2,3]*10]*10
class writable(object):
	def write(self, buf): pass
w = writable()
print('dumps: %.3f' % timeit.timeit(lambda: json.dumps(obj), number=10000))
print('dump:  %.3f' % timeit.timeit(lambda: json.dump(obj,w), number=10000))

On my machine this outputs:
dumps: 0.391
dump:  4.501

I believe this is mostly caused by dump using JSONEncoder.iterencode without _one_shot=True, resulting in c_make_encoder not being used.

----------
components: Extension Modules
messages: 136439
nosy: poq
priority: normal
severity: normal
status: open
title: json.dump much slower than dumps
type: performance
versions: Python 2.7, Python 3.2

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


More information about the Python-bugs-list mailing list