java - Calculating execution time of an algorithm -


i have developed image processing algorithm in core java (without using third party api), have calculate execution time of algorithm, have used system.currenttimemillis() that,

public class myalgo {     public myalgo(string imagepath){      long sttime = system.currenttimemillis();      // ..........................      // algorithm      // ..........................      long endtime = system.currenttimemillis();      system.out.println("time ==> " + (endtime - sttime));    }     public static void main(string args[]){      new myalgo("d:\\myimage.bmp");    } } 

but problem each time running program getting different execution time. can please suggest me how can this?

if don't want use external profiling libraries wrap algorithm in for() loop executes 1000 times , divide total time 1000. result more accurate since other tasks/processes out.

note: overall measure time reflect expected time of algorithm finish , not total time algorithms code instruction require. example if algorithm uses lot of memory , on average java vm calls garbage collector twice per each execution of algorithm - should take account time of garbage collector. for() loop does, results.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -