Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi there,

I haven't run your program, but here are my thoughts on what would be taking so long:

  • Communication with Excel over COM is very slow

The less you communicate with excel the faster your program will run. There is a very good ExcelWriter project where you can write .xlsx files without needing to open Microsoft Excel. It will run a bit faster than what you have here:

https://xlsxwriter.readthedocs.org/en/latest/index.html

Hi there,

I haven't run your program, but here are my thoughts on what would be taking so long:

  • Communication with Excel over COM is very slow

The less you communicate with excel the faster your program will run. There is a very good ExcelWriter project where you can write .xlsx files without needing to open Microsoft Excel. It will run a bit faster than what you have here:

https://xlsxwriter.readthedocs.org/en/latest/index.html

edit

The best way to check what is eating up the time in your program is to profile it. Profiling is very easy. Assuming the name of your script file is accc_multiple_reports.py

python -m cProfile -o output.profile accc_multiple_reports.py
python -m pstats output.profile

The first line runs Python through the profiling tool, it will take a measurement of how long every single function took to run. The second line invokes pstats which is a tool that can read the profiling results. Once you are in the profiling tool:

output.prof% sort time
output.prof% stats 10

Where output.prof% is just the prompt, kind of like >>> in the python command line. stats 10 will print a list of the 10 worst functions in your program sorted by the amount of time spent in it.

You will most likely find that the 80/20 rule holds true here and 80% of your time is spent in 20% of your code. Another interesting way to sort and show the results is by cumulative time:

output.prof% sort cumulative
output.prof% stats 10

You can use both cumulative and time sorting to work out which are the worst functions in your program. To exit just type quit.

This will definitely tell you what is slow in your program, and will do so very quickly, much faster than guessing. Next you can tell me what's slow in the program :)