Timing a method...

So, this has always bugged me, how does one go about using java, in my case netbeans 5.0, to time how long a method takes to run? Such as, I am counting and I want to know how long it takes to get to a number.

Also, could someone tell me how to use NetBeans as I would Dr.Java? Cause I like the ability to compile and than type stuff in down below in Dr.Java.

Thanks for your help,

Dumber_Child

Message was edited by:

dumber_child

[470 byte] By [dumber_childa] at [2007-10-2 20:10:13]
# 1

Hi,

You can either use a profiler, or add something like this to your code.

long start = System.currentTimeMillis();

// call the method which you want to time..

lend end = System.currentTimeMillis();

System.out.println("It took " + (end - start) + " ms");

Kaj

kajbja at 2007-7-13 22:50:47 > top of Java-index,Java Essentials,New To Java...