Question: / / * * * IN JAVA * * * What's the best way to use the getTime ( ) method to separate each different

//***IN JAVA*** What's the best way to use the getTime() method to separate each different operation to get their run times?
public class GetTimeOfOperations{
public static void main(String[] args){
int iterations =100;
getTime(10000000000L, iterations);
getTime(15000000000L, iterations);
getTime(19000000000L, iterations);
getTime(25000000000L, iterations);
getTime(29000000000L, iterations);
}
public static void getTime(long n, int iterations){
int v;
long startTime = System.currentTimeMillis();
for(long i =1; i <= n; i++){
v =5+5;
}
/*separate out the different operations to print out individual results
for(long i =1; i <= n; i++){
v =5-5;
}
for(long i =1; i <= n; i++){
v =5*5;
}
for(long i =1; i <= n; i++){
v =5/5;
}
for(long i =1; i <= n; i++){
v =5%5;
}
for(long i =1; i <= n; i++){
v =5^5;
}*/
long endTime = System.currentTimeMillis();
System.out.println("Average execution time for n ="+ n +" is "+
((endTime - startTime)/(long)iterations)+" milliseconds(//insert operation)");
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!