body_producer代码
def convert_list(li, datetime_format=consts.china_full_datetime_format,
zone_name=consts.default_zone_name):
out = []
for ele in li:
out.append(ele.to_json(datetime_format,
zone_name=zone_name,
request_handler=None))
return out
def body_producer(page_size=1000):
chunk = []
for ele in query_result:
chunk.append(ele)
if len(chunk) > page_size:
yield from convert_list(chunk)
chunk = []
if chunk:
yield from convert_list(chunk)
profile结果
35238157 function calls (35232213 primitive calls) in 51.559 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
324/1 0.025 0.000 51.559 51.559 {built-in method builtins.exec}
1 1.124 1.124 51.559 51.559 tmp.py:16()
39631 0.113 0.000 27.180 0.001 tmp.py:37(body_producer)
594465 0.856 0.000 15.790 0.000 Worksheet.py:1035(write)
594465 3.486 0.000 14.142 0.000 Row.py:228(write)
1 0.000 0.000 11.857 11.857 peewee.py:6729(__iter__)
1 0.000 0.000 11.857 11.857 peewee.py:1839(inner)
1 0.000 0.000 11.857 11.857 peewee.py:1914(execute)
1 0.000 0.000 11.857 11.857 peewee.py:2085(_execute)
1 0.000 0.000 11.857 11.857 peewee.py:3067(execute)
看样子是是因为peewee的问题,但是感觉xlwt还是慢呀