Solved What is the size of an actual HUGE loop?

Discussion in 'Plugin Development' started by samosaara, Jun 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    samosaara

    During my plugin development journey i've come across lot's of "Whiles" and "For's" but I always were careful with them to don't cause any lag, or more extensive resource usage. But, with the actual CPU's, RAM's what the size of an actual HUGE loop, who would cause the old warning, (or lag in general) nightmare of server owners:
    "[WARN] Can't keep up did the system time changed? 99239ms behind!" <<Not exactly BTW :p
     
  2. samosaara There isn't a "huge loop". It depends what you're doing in that loop that can cause the issue. If you're doing something simple like incrementing a value, it would take a whole lot of iterations for that to be noticeable. If you were doing something like executing an SQL statement, that could easily cause problems with the very first iteration. It depends on what you're doing, not the number of iterations.
     
  3. Offline

    samosaara

    Aaah, Nice, makes sense. But What "kind of" things can make a heavy loop?
     
  4. Offline

    RawCode

    please define what is heavy or huge loop.
    probably you just dont understand how java works.
     
  5. Offline

    1Rogue


    Code:java
    1. for (Heavy h = new Heavy(); h.isHeavy(); h.addWeight()) {
    2. //very heavy
    3. }
     
  6. Offline

    samosaara

    Lols, why don't you read the entire post first? You would have understood.
    Code:
    rawCode.readPost();
     
    java: cannot find symbol
      symbol:  method readPost()
      location: class org.forums.bukkit.RawCode 
    --------------
    EDIT: I didn't really meant heavy, lols sorry it was a typo at my language heavy also means extensive resource usage and shit '-' but lols I were nearly lynched for a typo
     
  7. Offline

    1Rogue


    You can't simply make up terms. "CPUs" and "Rams" required to not have a "heavy" loop is not only gibberish but contextual and completely irrelevant.

    Java has an abstraction layer for it to be able to run on any machine with a JVM, you don't make code to be less "CPU" instensive or use less ram, you write your code to be efficient and do less operations to be able to complete a task. This is called Time Complexity, and it's all about "how many raw statements must this perform to do a job".
     
    AdamQpzm and mythbusterma like this.
  8. Offline

    mythbusterma

    And on top of intense resource usage, you'll want to avoid preforming network queries or things of that nature in loops, or even on the main thread at all.

    If you're worried about a particular method taking too long, you can always time it using System.currentTimeMills() and figuring out how long it takes to execute, although keep in mind this is very dependent on the computer you're running it on.
     
    samosaara and AdamQpzm like this.
  9. Offline

    samosaara

    @1Rouge Kinda mean but thanks for dah info anyway. Sorry the shit I said I didn't know about't it (that's why I asked anyway) ;-;
    mythbusterma Oh, thanks! Learned a lot o/
    Thanks guy question answered
     
Thread Status:
Not open for further replies.

Share This Page