articles icon indicating copy to clipboard operation
articles copied to clipboard

一个关于数组循环嵌套的性能问题

Open axuebin opened this issue 8 years ago • 0 comments

应该是有两个数组,它们的长度不同。

const a = 500000;
const b = 1000;
for(let i=0;i<a;i++){
  for(let j=0;j<b;j++){
  }
}
for(let i=0;i<b;i++){
  for(let j=0;j<a;j++){
  }
}

关于上述两种循环嵌套的方式,哪种效率更好?

经过测试,是先小后大的效率更好,为什么?

todo

axuebin avatar Oct 25 '17 07:10 axuebin