clock cycle?

Is there a way to count clock cycles for an algorithm such as getting the clock value before the algorithm and getting again at the end and finding the difference?
[170 byte] By [gtrdude18a] at [2007-11-26 22:30:30]
# 1

Yes.

Try

long beginningTime = System.currentTimeMillis();

//*****************

RUN YOUR ALGORITHM

//*****************

long finishedTime = System.currentTimeMillis();

long difference = finishedTime - beginningTime;

Here is where I found the method.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html

lethalwirea at 2007-7-10 11:35:23 > top of Java-index,Java Essentials,New To Java...
# 2
ok cool, thanks
gtrdude18a at 2007-7-10 11:35:23 > top of Java-index,Java Essentials,New To Java...
# 3
well its returning 0 as of now. is there any reason the times would be the same?
gtrdude18a at 2007-7-10 11:35:23 > top of Java-index,Java Essentials,New To Java...
# 4
Perhaps the algorithm isn't a complex algorithm?Would you mind posting the code?I tried the code I gave you and it seemed to work fine.
lethalwirea at 2007-7-10 11:35:23 > top of Java-index,Java Essentials,New To Java...
# 5
well i moved the code into my main method that calls the algorithm, that solved the problem since i had put it in the class that contained the method with the algorithm.thanks
gtrdude18a at 2007-7-10 11:35:24 > top of Java-index,Java Essentials,New To Java...
# 6
well i moved the code into my main method that calls the algorithm, that solved the problem since i had put it in the class that contained the method with the algorithm.thanks
gtrdude18a at 2007-7-10 11:35:24 > top of Java-index,Java Essentials,New To Java...