`

Interesting interview question…

    博客分类:
  • Java
阅读更多

Today I was asked this question. We have 2 cases with code blocks A, B and C. These code block don't share any resources except an iterator (int i).

Please give 3 possible reasons why case 1 could be faster than case 2, and 3 possible reasons why case 2 could be faster than case 1:

case 1

for (i=0; i<N; ++i){
 A;
 B;
 C;
}

case 2

for (i=0; i<N; ++i){
 A;
}
for (i=0; i<N; ++i){
 B;
}
for (i=0; i<N; ++i){
 C;
}

Link:http://programmers.stackexchange.com/questions/64132/interesting-interview-question

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics