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..