• Post Reply Bookmark Topic Watch Topic
  • New Topic

How dose the loop impact the performance? How to measure?  RSS feed

 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I coded the following


My questions are:
1. Not sure if the number of loop (2000) is too big. Does it impact the performance in heavy load system?
2. How to measure the cost of loop? e.g. cost of resource, etc.
3. Should I have to decrease the loop number and increase the sleep interval for better performance?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to accomplish?

How does this affect resources? The best way to check that out would be to use a profiler and see how much time and other resources are tied up in the loop.

But how to optimize the code is impossible to say without info like what you are trying to do and the time resolution required to do it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a famous quote - "premature optimization is the root of all evil". Write what makes sense in terms of clean, understandable, easy to maintain code. then run it.

If you then have performance issues, start tuning. but use a profiler to find where the bottlenecks REALLY are, don't just guess, because you will guess wrong almost every time.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sort of looks like it's just waiting for some event to happen. If that's the case, there may be better ways to do it. At any rate if you explained the problem we might be able to give some useful answers (sorry fred!) and not have to guess what you're after.
 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all.

I post another thread as following for the other question:webpage

The code details:


My question: if I create the number 2000 to a larger number, will the loop impact the system performance (it is multithread server and about 200 sockets in my test env)?
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, I dont understand much about this, but I know, that you giving more sleeping time (like 5 ms) would probably work better, because then you'll let more time for other threads to run better, such as the garbage collector...

this can be a great help when you're not sure about timing.

also, performance will get worse if garbage collector cant do its work, this can be only a small thing, but repeated 2000 times can represent a big loss of performance.

i would suggest you the following:

calculate the time you spend on one loop, then, by this time, calculate the sleep time...
with this, if your executing speed of one loop decreases, you'll probably want the thread to sleep a few ms more, so that you can collect garbage.


this is useful when you're not sure about the garbage collection of your system.


also I dont know much about this, is only my suggestion.


hope I could help!

regards.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!