Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stopwatch
- {
- private long t;
- private double a;
- private double z;
- public Stopwatch()
- {
- t = System.currentTimeMillis();
- a = 0;
- z = 0;
- }
- public double elapsedTime()
- {
- return (System.currentTimeMillis() - t) / 1000.0;
- }
- public double[] stop()
- {
- //currentlap
- z = elapsedTime();
- //total
- a += z;
- t = System.currentTimeMillis();
- double[] x = {a, z};
- return x;
- }
- public void restart()
- {
- t = System.currentTimeMillis();
- }
- public static void main(String[] args)
- {
- int N = Integer.parseInt(args[0]);
- double totalMath = 0.0;
- Stopwatch swMath = new Stopwatch();
- for (int i = 0; i < N; i++)
- {
- totalMath += Math.sqrt(i);
- }
- double timeMath = swMath.elapsedTime();
- double totalNewton = 0.0;
- Stopwatch swNewton = new Stopwatch();
- for (int i= 0; i < N; i++)
- {
- totalNewton += Newton.sqrt(i);
- }
- double timeNewton = swNewton.elapsedTime();
- StdOut.println(totalNewton/totalMath);
- StdOut.println(timeNewton/timeMath);
- }
- }
Add Comment
Please, Sign In to add comment