Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

any resource or performance (memory or cpu) issue does this code present ?

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a code like



When N is big number, the code keeps looping for N times. My question is --- when program loops for N times, does it eat lot of memory or what ? what kind resource problem it may cause when N is big ? what kind of performance problem it may cause (ignore the time that it takes toloop, that's not an issue) ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

when program loops for N times, does it eat lot of memory or what ?

This is the sort of question that is best answered empirically. What did you observe when you ran it?

 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It probably doesn't require a lot of memory; the many numbers can all fit into one int space, which is updated every iteration.
I suggest you change it to read
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic