我知道有办法知道周期或迭代语句的成本,但我想知道两件事:
第一个。 这两个上市哪个更划算?(或者如果有更好的方法,我全神贯注):
更新:然后问题是:他们中的哪两个会正确使用内存/GC?请记住,下一个循环不需要reqObj
和的“值”。resObj
for (TransactionLog transactionLog : transactionLogList) {
RequestObj reqObj = new RequestObj();
ResponseObj resObj;
try {
//do things with these 2 babes and the transactionLog
} catch (WhateverException ex) {
log.error("Error in XYZ while doing whatever", ex);
//execute code without throwing anything up
} finally {
reqObj = null;
resObj = null;
}
}
或者
RequestObj reqObj = new RequestObj();
ResponseObj resObj;
for (TransactionLog transactionLog : transactionLogList) {
try {
//do things with these 2 babes and the transactionLog
} catch (WhateverException ex) {
log.error("Error in XYZ while doing whatever", ex);
//execute code without throwing anything up
} finally {
//do something
}
}
和第二。 我在哪里可以找到一个好地方/书/网站来学习这个“算法最佳实践”和函数 O(letter) 来计算交互的语句成本?
PD:对不起我的英语……他不是很好看。xD