I’m working on a web service project that involves pictures, a lot of pictures. So I’ve been thinking on what was the best way to store information about a picture? I found 3 possibilities:
1. Store the information in a database. It’s the most obvious solution. When you need the information, you get it from the database. Easy. BUT databases are known to slow down web services…
2. Store the information in a separated file. So you would have the JPEG and its data file. You display the first one and get the informations needed from the second one.
3. Use the EXIF data directly. JPEG have metadata, structured under the EXIF methods. It’s easy to get those informations out of the JPEG file with PHP code for example.
So who’s the fastest?

DataFile comes first, followed by the DataBase and last comes the Exif.
I’m not surprised by the poor performance of the EXIF. Bigger surprise is the good performance of the DataFile. I was assuming that having to open an external file and load its content would always be slower than getting the same content from a database.
By the way, to obtain these figures I run a test through 100 pictures, with each of the 3 methods mentioned. Detailed times are as following:
- Database method processed in 0.00260901451111 seconds
- Separate data file method processed in 0.00199389457703 seconds
- EXIF method processed in 0.0521869659424 seconds
So storing the information in a separate data file is the fastest method. However I don’t think it will be the one that I will use. The reason is that I reckon the lake of flexibility using such method wont compensate the little performance tweak. So it seems that database is definitely the best option. It took me a couple of hours to be certain about it. Now I can go on
If you enjoyed this post, make sure you subscribe to my RSS feed!












Recent Comments