public static void main(String[] args){
int[] nums;
int n = 1000000;
int m = 1000;
List<Long> results = new ArrayList<Long>();
Instant before, after;
long delta;
// for(int i = 0; i < 5; i++){
// nums = IntStream.rangeClosed(1, n).toArray();
// shuffle(nums);
// before = Instant.now();
// findKthSmallest(nums, m);
// quickSort(nums,0 , m-1);
// after = Instant.now();
// delta = Duration.between(before, after).toMillis();
// System.out.println(delta);
// }
nums = IntStream.rangeClosed(1, n).toArray();
shuffle(nums);
before = Instant.now();
findKthSmallest(nums, m);
quickSort(nums,0 , m-1);
after = Instant.now();
delta = Duration.between(before, after).toMillis();
System.out.println(delta);
}
In the main method, I tried to print out delta 5 times. When I did it inside the loop (commented-out block), the delta decreased over time, which is weird. When I did it outside the loop (run the code 5 times), the deltas seem to be consistent. Why is this happening and how can I fix it? Thank you.