SHARE
TWEET

Untitled

a guest Feb 27th, 2020 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Collections;
  4. import java.util.Random;
  5.  
  6. public class Main
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         int size = 10000000;
  11.         int[] arr = new int[size];
  12.        
  13.         Random rand = new Random();
  14.        
  15.         for (int i = 0; i < size; i++)
  16.         {
  17.             arr[i] = rand.nextInt(10000);
  18.         }
  19.        
  20.         long start = System.nanoTime();
  21.         Arrays.sort(arr);
  22.         long stop = System.nanoTime();
  23.        
  24.         System.out.println((stop - start)/10e+6 + " milliseconds");
  25.        
  26.         ArrayList<Integer> li = new ArrayList<>();
  27.        
  28.         int i = 0;
  29.         while (i < size)
  30.         {
  31.             li.add(rand.nextInt(10000));
  32.             i++;
  33.         }
  34.        
  35.         start = System.nanoTime();
  36.         Collections.sort(li);
  37.         stop = System.nanoTime();
  38.        
  39.         System.out.println((stop - start)/10e+6 + " milliseconds");
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top