isefire icon

StopwatchExtended

isefire | PRO | 07/28/14 02:40:05 AM UTC | 0 ⭐ | 440 👁️ | Never ⏰ | []
Java |

970 B

|

None

|

0 👍

/

0 👎

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);
    }
}

Comments