我几乎到处寻找这种奇怪情况的可能答案,但没有运气。我有 1000 个文件(每个 14 个字节,用于测试目的)位于我的应用程序 Documents 目录内的文件夹中。使用下面的代码,我获取文件夹的内容,遍历每个文件 URL,创建一个自定义模型对象来表示名为 FFFile 的文件并将其存储到容器数组中。为了清楚起见,我简化了这种方法。
这一切都很好,并且符合我的预期,但是,最奇怪的是,这段代码在 iPhone 5 上执行需要 0.775 秒,而在 iPhone 5S 上执行需要 2.378 秒!一般的假设是 iPhone 5S 会更快,不是吗?两台设备都使用完全相同的文件、文件夹结构、代码等...
我对 iPhone 5S 的 64 位架构如何影响以下代码的性能没有非常广泛的了解,因此任何对这种奇怪案例(无论如何对我来说都很奇怪)的见解将不胜感激。谢谢参观。
更新:iPhone 5 和 iPhone 5S 都运行 iOS 7.0.3。
static NSArray *keys;
keys = @[
NSURLNameKey,
NSURLTypeIdentifierKey,
NSURLLocalizedTypeDescriptionKey,
NSURLIsDirectoryKey,
NSURLCreationDateKey,
NSURLContentModificationDateKey,
NSURLFileSizeKey,
];
// url = ".../Documents/Folder/";
NSMutableArray *fileContainer = [NSMutableArray new];
NSArray *results = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:url includingPropertiesForKeys:keys options:0 error:nil];
for (NSURL *url in contents) {
NSDictionary *properties = [url resourceValuesForKeys:keys error:nil];
FFFile *file = [[FFFile alloc] init];
file.fileURL = url;
file.isDirectory = [properties[NSURLIsDirectoryKey] boolValue];
file.filename = properties[NSURLNameKey];
file.fileSize = properties[NSURLFileSizeKey];
file.typeIdentifier = properties[NSURLTypeIdentifierKey];
file.typeDescription = properties[NSURLLocalizedTypeDescriptionKey];
file.creationDate = properties[NSURLCreationDateKey];
file.modificationDate = properties[NSURLContentModificationDateKey];
[fileContainer addObject:file];
}