我一直在使用ReportLab生成报告,并且在分析过程中,我发现doc.build(story)方法花费了95%的渲染时间。具体来说,我认为rl_accel是C扩展名。
对于那些可能更熟悉ReportLab内部工作原理的人来说,是否有C语言编译器可使此rl_accel方法更快?这是我的cProfile输出:
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
2335735 15.376 0.000 19.258 0.000 {built-in method reportlab.lib._rl_accel.instanceStringWidthT1}
2335735 3.776 0.000 25.628 0.000 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\pdfbase\pdfmetrics.py:747(stringWidth)
429 3.442 0.008 28.225 0.066 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\platypus\paragraph.py:1001(_splitWord)
2338255 2.098 0.000 2.098 0.000 {built-in method _codecs.charmap_encode}
2337984 1.802 0.000 3.900 0.000 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\pdfbase\rl_codecs.py:999(encode)
2335735 1.650 0.000 20.908 0.000 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\pdfbase\pdfmetrics.py:362(stringWidth)
2337523 0.944 0.000 0.945 0.000 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\pdfbase\pdfmetrics.py:706(getFont)
5 0.288 0.058 0.288 0.058 {method 'execute' of 'pyodbc.Cursor' objects}
78 0.187 0.002 29.391 0.377 C:\Users\administrator.user\Desktop\FlaskReportApp\venv\lib\site-packages\reportlab\platypus\paragraph.py:1734(breakLines)
109 0.124 0.001 0.124 0.001 {built-in method nt.lstat}
此报告最终长达24页,包含约103,000个字符。
谢谢!