public class Main

{

static void linearFunction(int n)

{

long start = System.currentTimeMillis();

for(int i = 0; i < n; i++);

long end=System.currentTimeMillis();

long elapsedTime = end – start;

System.out.println(“Elapsed time taken by linear function for “+n+ ” iterations: “+elapsedTime);

}

static void quadraticFunction(int n)

{

long start = System.currentTimeMillis();

for(int i = 0 ; i <n;i++)

for(int j = 0; j < n; j++);

long end=System.currentTimeMillis();

long elapsedTime = end – start;

System.out.println(“Elapsed time taken by quadratic function for “+n+” iterations: “+elapsedTime);

}

static void cubicFunction(int n)

{

long start= System.currentTimeMillis();

for(int i = 0 ; i <n;i++)

for(int j = 0; j < n; j++)

for(int k = 0; k <n; k++);

long end=System.currentTimeMillis();

long elapsedTime = end – start;

System.out.println(“Elapsed time taken by cubic function for “+n+” iterations: “+elapsedTime);

}

public static void main(String[] args) {

//System.out.println(“Hello World”);

System.out.println(“Calling linear function for 1000 iterations”);

linearFunction(1000);

System.out.println(“Calling quadratic function for 1000 iterations”);

quadraticFunction(1000);

System.out.println(“Calling cubic function for 1000 iterations”);

cubicFunction(1000);

System.out.println(“——————————————–“);

System.out.println(“Calling linear function for 10000 iterations”);

linearFunction(10000);

System.out.println(“Calling quadratic function for 10000 iterations”);

quadraticFunction(10000);

System.out.println(“Calling cubic function for 10000 iterations”);

cubicFunction(10000);

System.out.println(“——————————————–“);

System.out.println(“Calling linear function for 100000 iterations”);

linearFunction(100000);

System.out.println(“Calling quadratic function for 100000 iterations”);

quadraticFunction(100000);

System.out.println(“Calling cubic function for 100000 iterations”);

cubicFunction(100000);

System.out.println(“——————————————–“);

System.out.println(“Calling linear function for 500000 iterations”);

linearFunction(500000);

System.out.println(“Calling quadratic function for 500000 iterations”);

quadraticFunction(500000);

System.out.println(“Calling cubic function for 500000 iterations”);

cubicFunction(500000);

System.out.println(“——————————————–“);

}

}

—————————————————————————–

//output

Calling linear function for 1000 iterations

Elapsed time taken by linear function for 1000 iterations: 0

Calling quadratic function for 1000 iterations

Elapsed time taken by quadratic function for 1000 iterations: 6

Calling cubic function for 1000 iterations

Elapsed time taken by cubic function for 1000 iterations: 11

——————————————–

Calling linear function for 10000 iterations

Elapsed time taken by linear function for 10000 iterations: 0

Calling quadratic function for 10000 iterations

Elapsed time taken by quadratic function for 10000 iterations: 1

Calling cubic function for 10000 iterations

Elapsed time taken by cubic function for 10000 iterations: 50

——————————————–

Calling linear function for 100000 iterations

Elapsed time taken by linear function for 100000 iterations: 2

Calling quadratic function for 100000 iterations

Elapsed time taken by quadratic function for 100000 iterations: 0

Calling cubic function for 100000 iterations

Elapsed time taken by cubic function for 100000 iterations: 0

——————————————–

Calling linear function for 500000 iterations

Elapsed time taken by linear function for 500000 iterations: 3

Calling quadratic function for 500000 iterations

Elapsed time taken by quadratic function for 500000 iterations: 0

Calling cubic function for 500000 iterations

Elapsed time taken by cubic function for 500000 iterations: 0

——————————————–