Make `pdfautnup` faster
Panelizing label.pdf takes more than 20 seconds. I wonder how pdfautonup could be faster.
$ time pdfautonup --algorithm panel --margin 1cm --gap .5cm --size A4 label.pdf
real 0m23.755s
user 0m23.664s
sys 0m0.056s
Profiling gives:
Fri Feb 19 23:00:49 2016 profile
15330181 function calls (15310277 primitive calls) in 40.225 seconds
Ordered by: cumulative time
List reduced from 1248 to 30 due to restriction <30>
ncalls tottime percall cumtime percall filename:lineno(function)
95/1 0.006 0.000 40.225 40.225 {built-in method builtins.exec}
1 0.000 0.000 40.225 40.225 pdfautonup:3(<module>)
1 0.000 0.000 39.706 39.706 pdfautonup/__main__.py:145(main)
1 0.000 0.000 39.698 39.698 pdfautonup/__main__.py:98(nup)
42 0.001 0.000 39.305 0.936 pdfautonup/geometry.py:47(add_page)
42 0.000 0.000 39.304 0.936 PyPDF2/pdf.py:2334(mergeTranslatedPage)
42 0.038 0.001 39.304 0.936 PyPDF2/pdf.py:2286(mergeTransformedPage)
42 0.004 0.000 39.266 0.935 PyPDF2/pdf.py:2212(_mergePage)
167 0.003 0.000 39.239 0.235 PyPDF2/pdf.py:2632(__init__)
167 5.234 0.031 31.545 0.189 PyPDF2/pdf.py:2647(__parseContentStream)
83 0.001 0.000 19.275 0.232 PyPDF2/pdf.py:2166(_pushPopGS)
293808/276964 3.387 0.000 16.599 0.000 PyPDF2/generic.py:54(readObject)
269768 1.600 0.000 9.268 0.000 PyPDF2/generic.py:264(readFromStream)
168 1.747 0.010 8.041 0.048 PyPDF2/pdf.py:2724(_getData)
409771 4.254 0.000 7.980 0.000 PyPDF2/utils.py:120(readUntilRegex)
176 0.001 0.000 7.685 0.044 PyPDF2/generic.py:818(getData)
2976419 4.357 0.000 5.074 0.000 PyPDF2/utils.py:231(b_)
123274 0.594 0.000 2.704 0.000 PyPDF2/generic.py:243(writeToStream)
415623 1.677 0.000 2.567 0.000 PyPDF2/utils.py:89(readNonWhitespace)
1914520 2.081 0.000 2.081 0.000 {method 'read' of '_io.BytesIO' objects}
9250 0.330 0.000 1.824 0.000 PyPDF2/generic.py:149(readFromStream)
1388997 1.792 0.000 1.792 0.000 {method 'seek' of '_io.BytesIO' objects}
120546 0.493 0.000 1.357 0.000 PyPDF2/generic.py:227(__new__)
276023 0.491 0.000 1.301 0.000 {built-in method builtins.repr}
9458 0.121 0.000 1.260 0.000 PyPDF2/generic.py:142(writeToStream)
152737 0.688 0.000 1.209 0.000 PyPDF2/generic.py:261(writeToStream)
410120 0.977 0.000 0.977 0.000 {method 'search' of '_sre.SRE_Pattern' objects}
13236 0.324 0.000 0.970 0.000 PyPDF2/generic.py:441(writeToStream)
920184/919814 0.935 0.000 0.936 0.000 {built-in method builtins.len}
12942 0.294 0.000 0.933 0.000 PyPDF2/generic.py:321(readStringFromStream)
Good luck!