I know how to measure the time a method takes to execute and finish. But what if I have 10 different methods and I want to measure how much time each of the 10 methods take to run. It will be inefficient for me to keep writing System.currentTimeMillis()
twenty times.
So I am just wondering is there a more efficient method to this problem, i.e. create a method that measure the time it takes for a particular method to run and that particular method will be passed as a parameter (This is an idea on top of my head and I can be completely wrong about this) ?
long startTime = System.currentTimeMillis();
// Create graph and read file
Graph dag = new Graph();
read_file(dag, "FILE.txt");
long endTime = System.currentTimeMillis();
System.out.println("Load file: " + (endTime - startTime) + " milliseconds");
// Transposing graph
startTime = System.currentTimeMillis();
Graph dag_rev = new Graph();
Graph dag_transposed = dag_rev.transposed(dag);
endTime = System.currentTimeMillis();
System.out.println("Transposing graph: " + (endTime - startTime) + " milliseconds");