InsertionTest.java
public class InsertionTest
{
public static double timeTrials(int M, int N)
{
Double[] a = new Double[N];
double total = 0;
for (int k = 0; k < M; k++)
{
for (int i = 0; i < N; i++)
a[i] = Math.random();
Stopwatch s = new Stopwatch();
Insertion.sort(a);
total += s.elapsedTime();
}
return total;
}
public static void main(String[] args)
{
int M = Integer.parseInt(args[0]);
double prev = timeTrials(M, 512);
for (int N = 1024; true; N += N)
{
double curr = timeTrials(M, N);
StdOut.printf("%7d %4.2f\n", N,
curr / prev);
prev = curr;
}
}
}
No comments:
Post a Comment