Thread: Optimize cycle

Results 1 to 2 of 2
  1. #1 Optimize cycle 
    Officially Running

    Mr Dream's Avatar
    Join Date
    Dec 2013
    Posts
    1,922
    Thanks given
    555
    Thanks received
    295
    Rep Power
    905
    Is there anyway to optimize this code since it keeps calling
    Code:
    System.out.println("[WARNING]: Server load: " + cycle + "%!");
    very often

    Code:
     /**
         * Sleeps for the cycle delay.
         *
         * @ThroWs InterruptedException
         */
        private void sleep() {
            try {
                long sleepTime = cycleRate - cycleTimer.elapsed();
                boolean sleep = sleepTime > 0 && sleepTime < 600;
                for (int i = 0; i < PacketManager.SIZE; i++) {
                    Benchmark b = PacketManager.packetBenchmarks[i];
                    if (!sleep && b.getTime() > 0) {
                        System.out.println("Packet " + i + "[" + PacketManager.packets[i].getClass().getSimpleName() + "] took " + b.getTime() + " ms.");
                    }
                    b.reset();
                }
                if (sleep) {
                    Benchmarks.resetAll();
                    //System.out.println("[ENGINE]: Sleeping for " + sleepTime + "ms");
                    Thread.sleep(sleepTime);
                } else {
                    // The server has reached maximum load, players may now lag.
                    long cycle = 100 + ((Math.abs(sleepTime) - cycleRate) / 6);
                    /*if (cycle > 999) {
                        initiateRestart();
                    }*/
                    System.out.println("[WARNING]: Server load: " + cycle + "%!");
                    Benchmarks.printAll();
                    Benchmarks.resetAll();
                    System.out.println("");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
    
            } finally {
                cycleTimer.reset();
            }
        }
    Attached image
    Attached image
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Mr Dream View Post
    Is there anyway to optimize this code since it keeps calling
    Not that piece of code no, the code that's actually executed each tick, I'm sure there's many improvements you can make
    Reply With Quote  
     

  3. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [Project] Cycling game (GUI)
    By w::v::d in forum Application Development
    Replies: 1
    Last Post: 06-05-2009, 11:02 PM
  2. Cleaned/optimized/packaged WinterLove
    By Raśl in forum Downloads
    Replies: 39
    Last Post: 06-01-2009, 04:04 AM
  3. Replies: 26
    Last Post: 05-26-2009, 03:55 PM
  4. RuneScape cycle time.
    By Stanyer in forum RS2 Server
    Replies: 4
    Last Post: 04-09-2008, 05:00 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •