I have implemented a protocol and it is executed and give me the output I want but the problem is the runtime execution. Is a little more than I would expected. I wanted to measure the execution time of one of my methods of the class but I am not sure if what I have done is correct since I do not have much experience in testing.
What I have done is:
public class MyClass {
// some private fields here
public int method toBeMeasured (int a){
long startTime=System.nanoTime();
// the code under my method including
// some for cycles and some operation.
long finalTime=System.nanoTime() - startTime;
return something of type int;
}
}
Now what I need to know if the result I got is really telling me the performance speed of this method or am I measuring it wrong. Also I want to know how can I measure this 10000 times and take the average of those times. I hope to receive any feedback for my question.