核心数据性能:NSPredicate比较对象

ma1*_*w28 8 profile performance core-data nspredicate nsfetchrequest

如果我的Author NSManagedObject模型有一个authorID属性(由服务器确定),NSFetchRequest如果NSPredicate过滤器authorID而不是完整Author对象,那么效果会更好吗?让我们说我正在取得所有Book NSManagedObject的东西author.哪个predicateFormat更好?

[NSPredicate predicateWithFormat:@"author = %@", anAuthor]
Run Code Online (Sandbox Code Playgroud)

要么

[NSPredicate predicateWithFormat:@"author.authorID = %@", anAuthor.authorID]
Run Code Online (Sandbox Code Playgroud)

对此进行分析的最佳方式是什么?我使用OCUnit(SenTestingKit)进行核心数据测试.iOS有像Ruby的Benchmark模块吗?

pau*_*ley 1

可能值得使用 参数来运行您的应用程序-com.apple.CoreData.SQLDebug 1,如此处详述

然后,您可以查看 Core Data 是否在两种情况下执行相同的 SQL(假设您使用的是 SQLite 存储)。