Java Date benchmark how long to sort an array

Description

Java Date benchmark how long to sort an array

import java.util.Arrays;
import java.util.Date;
import java.util.Random;

public class Main {
  public static void main(String[] args) {
    int[] anArray = new int[100000];
    Random generator = new Random();
    for (int i = 0; i < 100000; i++) {
      anArray[i] = (generator.nextInt(100000) + 1);
    }/*from w  ww . j a  v  a  2 s  . co m*/
    Date before = new Date();
    Arrays.sort(anArray);
    Date after = new Date();
    System.out.println("milli seconds:" + (after.getTime() - before.getTime()));
  }
}



PreviousNext

Related