0
有没有办法告诉NSOperation已经执行了多久?如何判断NSOperation执行的时间?
for (NSOperation *operation in [self.operationQueue operations]) {
// how to tell how long the operation has been executing?
}
有没有办法告诉NSOperation已经执行了多久?如何判断NSOperation执行的时间?
for (NSOperation *operation in [self.operationQueue operations]) {
// how to tell how long the operation has been executing?
}
使两个变量NSTimeInterval。
NSTimeInterval t1, t2;
当操作开始运行:
t1 = NSTimeIntervalSince1970;
,当它完成
t2 = NSTimeIntervalSince1970;
那么你根本就
NSTimeInterval t3 = t2 -t1;
不,你知道多少秒这个确实跑了。这很粗糙,也许有更好的方法来获得确切的数字,但我会建议你使用一个像仪器这样的分析器。
但是这是一个很好的方法,因为它非常简单,并且不会像任何分析器那样带走任何CPU功耗。
我也建议搜索标准C库的一些CPU蜱或接近的东西。
享受。
如果是自定义子类,只需添加一个ivar,'startDate'。 –