-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSort.java
More file actions
33 lines (32 loc) · 789 Bytes
/
MSort.java
File metadata and controls
33 lines (32 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Random;
import java.util.Arrays;
public class MSort {
static int n = 1000000;
static String arr[] = new String[n];
static Random rand = new Random(n);
private static void ShuffleArray(String[] array)
{
int index;
String temp;
for (int i = array.length - 1; i > 0; i--)
{
index = rand.nextInt(i + 1);
temp = array[index];
array[index] = array[i];
array[i] = temp;
}
}
public static void main( String arg[] ) {
for (int i = 0; i < n; i++)
arr[i] = "" + rand.nextInt(n);
System.gc();
System.out.println("start");
long tim = System.currentTimeMillis();
for(int i = 0; i < 100; i++) {
Arrays.sort(arr);
ShuffleArray(arr);
}
long dur = (long) (System.currentTimeMillis()-tim);
System.out.println("time "+dur);
}
}