Title: imghdr test order makes it slow
Type: performance Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, biny
Priority: normal Keywords:

Created on 2008-07-22 09:30 by biny, last changed 2008-08-16 16:29 by benjamin.peterson. This issue is now closed.

File name Uploaded Description Edit
current biny, 2008-07-23 05:38 Unoptimized
optimized biny, 2008-07-23 05:38 optimized
Messages (6)
msg70142 - (view) Author: Ilpo Nyyssönen (biny) Date: 2008-07-22 09:30
The order of tests in imghdr makes it slow in common cases. Even without
any statistics it is quite easy to see that jpeg is the most common
format. In imghdr only bmp and png are after it. Also, should png really
be the last one?

Nearly all digital cameras produce jpegs and handling such images is one
big use case for this module.

Changing the test order should be easy and have big effect in common use
msg70146 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-22 12:36
Do you have any benchmarks to prove this with? IMO, the difference would
be extremely insignificant.
msg70168 - (view) Author: Ilpo Nyyssönen (biny) Date: 2008-07-23 05:38
Naturally it requires a big amount of files. Getting big amount of jpegs
is easy. Getting big amount of pbms or rgbs is not so easy.

I'll attach two profiling runs showing some difference when test_jpeg
and test_exif are moved to be the first tests. The beginnings those
outputs show the return value counts.
msg70507 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-31 14:27
Ok. Would you like to propose an alternate order?
msg70649 - (view) Author: Ilpo Nyyssönen (biny) Date: 2008-08-03 05:24

and then the rest
msg71224 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-16 16:29
Done in r65713.
Date User Action Args
2008-08-16 16:29:28benjamin.petersonsetstatus: open -> closed
resolution: accepted
messages: + msg71224
2008-08-03 05:24:48binysetmessages: + msg70649
2008-07-31 14:27:29benjamin.petersonsetstatus: pending -> open
messages: + msg70507
2008-07-23 05:38:56binysetfiles: + optimized
2008-07-23 05:38:17binysetfiles: + current
messages: + msg70168
2008-07-22 12:36:39benjamin.petersonsetstatus: open -> pending
nosy: + benjamin.peterson
messages: + msg70146
2008-07-22 09:30:38binycreate