Question: (JAVA) Write code that compares the speed of your MyMath.sqrt with Math.sqrt in the way specified below. This code should go into the public static

(JAVA) Write code that compares the speed of your MyMath.sqrt with Math.sqrt in the way specified below. This code should go into the public static member function named main with return type void.

Using a loop, evaluate Math.sqrt on 10, 000, 000 random numbers between 0 and 100. These random numbers should be generated by calling 100*Math.random(). Measure the time it takes to complete this task using System.currentTimeMillis. Do the same with MyMath.sqrt. You may want to consult: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis()

This time measurement includes the time it takes to generate the random numbers. With a separate loop, measure the time it takes to generate the random numbers without evaluating the square root. Putting these measurement together, output, to the command line, the average execution time per evaluation of the two square root functions with the execution time of the random number generation subtracted out.

You will see that Math.sqrt is far superior over MyMath.sqrt. This is to be expected since standard math functions like Math.sqrt are implemented and optimized by a group of experts over many hours.

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 Databases Questions!