Just for the record ...
I have tried this:
for ( NSString* filename in imagefiles )
{
NSURL * imgurl = [NSURL fileURLWithPath: filename isDirectory: NO];
CGImageSourceRef sourceref = CGImageSourceCreateWithURL( (__bridge CFURLRef) imgurl, NULL );
}
This takes 1 minute for around 300k images stored on my internal SSD.
That would be OK.
However! .. if performed on a folder stored on an external hard disk, I get the following timings:
- 20 min for 150k images (45 GB)
- 12 min for 150k images (45 GB), second time
- 150 sec for 25k images (18 GB)
- 170 sec for 25k images (18 GB), with the lines below (*)
- 80 sec for 22k (3 GB) images
- 80 sec for 22k (3 GB) images, with the lines below (*)
All experiments were done on different folders on the same hard disk, WD MyPassport Ultra, 1 TB, USB-A connector to Macbook Air M2.
Timings with the same number of files/GB were the same folders, resp.
(*): these were timings where I added the following lines to the loop:
CFDictionaryRef fileProps = CGImageSourceCopyPropertiesAtIndex( image, 0, NULL );
bool success = CFDictionaryGetValueIfPresent( fileProps, kCGImagePropertyExifDictionary, (const void **) & exif_dict );
CFDictionaryGetValueIfPresent( exif_dict, kCGImagePropertyExifDateTimeDigitized, (const void **) & dateref );
iso_date = [isoDateFormatter_ dateFromString: (__bridge NSString * _Nonnull)(dateref) ];
[datesAndTimes_ addObject: iso_date ];
(Plus some error checking, which I omit here.)
First of all, we can see that the vast majority of time is spent on CGImageSourceCreateWithURL().
Second, there seem to be some caching effects, although I have a hard time understanding that, but that is not the point.
Third, the durations are not linear; I guess it might have something to do with the sizes of the files, too, but again, didn't investigate further.
So, it looks to me like CGImageSourceCreateWithURL() really loads the complete image file.
I don't see why Ole Bergmann can claim his approach does not load the whole image.