Thread: Find out how long it takes to do something

Results 1 to 8 of 8
  1. #1 Find out how long it takes to do something 
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Right, ever wanted to know how many ms it takes a player to login, or how long it takes your server to do something so then you can see if anything you do creates a speed increase or decrease? If you follow this tutorial you can...

    First create a class called ProcessContainer, put this in:

    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package com.nathanroys.irc.processing;
    
    /**
     *
     * @author Nathan
     */
    public class ProcessContainer {
    
        public static ProcessContainer instance = new ProcessContainer();
        public static long processTime;
    
        public static ProcessContainer getInstance() {
            return instance;
        }
    
        public long processTime(Processer p) {
            long startTime = System.currentTimeMillis();
            p.process();
            processTime = System.currentTimeMillis() - startTime;
            return processTime;
        }
    }
    Then create a new class called Processer, put this in it~:
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package com.nathanroys.irc.processing;
    
    /**
     *
     * @author Nathan
     */
    public interface Processer {
    
        public void process();
    }
    Now, to see how long it has taken to do something you would do the following:

    Code:
            System.out.println("Completed in "+
                            ProcessContainer.getInstance().processTime(new Processer() {
    
                @Override
                public void process() {
                      sendMessage("Hey");
                }
            })+"ms"
            );
    Or just:
    Code:
            ProcessContainer.getInstance().processTime(new Processer() {
    
                @Override
                public void process() {
                       sendMessage("Hey dude");
                }
            });
               System.out.println("Took " + ProcessContainer.processTime + "ms taken to execute!");
    Hope this helps a few people..
    Reply With Quote  
     

  2. #2  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,881
    Thanks given
    1,854
    Thanks received
    4,741
    Rep Power
    5000
    It's more simple to do

    Code:
    int startTime = System.currentTimeMillis();
    //Stuff here
    int endTime = System.currentTimeMillis();
    System.out.println("Action finished in "+(endTime - startTime)+"ms.");



    Reply With Quote  
     

  3. #3  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by S Quare Quxx View Post
    It's more simple to do

    Code:
    int startTime = System.currentTimeMillis();
    //Stuff here
    int endTime = System.currentTimeMillis();
    System.out.println("Action finished in "+(endTime - startTime));
    More simple - yes... Better for performance and general tidyness of your code - no.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Nov 2008
    Posts
    2,180
    Thanks given
    148
    Thanks received
    99
    Rep Power
    2004
    OOoo That's cool.
    Reply With Quote  
     

  5. #5  
    Sub
    Sub is offline
    sυввч

    Sub's Avatar
    Join Date
    Aug 2007
    Age
    21
    Posts
    4,325
    Thanks given
    1,082
    Thanks received
    346
    Discord
    View profile
    Rep Power
    2755
    oh teh sex
    Reply With Quote  
     

  6. #6  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    Quote Originally Posted by Cascade View Post
    More simple - yes... Better for performance and general tidyness of your code - no.
    Not sure how its better performance if his uses two variables and a println when yours uses a lot more...
    Reply With Quote  
     

  7. #7  
    Community Veteran

    Cascade's Avatar
    Join Date
    Oct 2006
    Posts
    1,023
    Thanks given
    12
    Thanks received
    27
    Rep Power
    912
    Quote Originally Posted by bloodargon View Post
    Not sure how its better performance if his uses two variables and a println when yours uses a lot more...
    Because he would put those on everything he wants to time, on the other hand with mine all you need to do is just re-use those classes.

    Don't come here acting like a smart arse, cause your not.. rofl.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Jan 2009
    Age
    26
    Posts
    119
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Already have nice though rep
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •