This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imghdr test order makes it slow
Type: performance Stage:
Components: Library (Lib) Versions: Python 2.5
process
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 2022-04-11 14:56 by admin. This issue is now closed.

Files
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
cases.
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
jpeg
exif
png
gif
tiff

and then the rest
msg71224 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-16 16:29
Done in r65713.
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47674
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