package foam.util;

import java.util.Comparator;
import java.util.Random;

public class QuickSortBenchmark {
  private static int count = 1;

  public static void main( String[] args) {
    // compare two algorithms for full sort
    runBenchmark(100000, 0, 100000);
    runBenchmark(200000, 0, 200000);
    runBenchmark(300000, 0, 300000);
    runBenchmark(400000, 0, 400000);
    runBenchmark(500000, 0, 500000);
    runBenchmark(600000, 0, 600000);

    // benchmark range
    runBenchmark( 1000000, 0, 20);
    runBenchmark( 2000000, 0, 20);
    runBenchmark( 4000000, 0, 20);
    runBenchmark( 8000000, 0, 20);
    runBenchmark(16000000, 0, 20);
    runBenchmark(32000000, 0, 20);

    runBenchmark(1000000, 100, 1000000);
    runBenchmark(2000000, 200, 2000000);
    runBenchmark(3000000, 300, 3000000);
    runBenchmark(4000000, 400, 4000000);
    runBenchmark(5000000, 500, 5000000);
    runBenchmark(6000000, 600, 6000000);
    runBenchmark(7000000, 700, 7000000);
    runBenchmark(8000000, 800, 8000000);
  }

  private static void benchmarkQuickSort(Integer[] array, int skip, int limit) {
    Arrays arr = new Arrays();
    long startTime = System.currentTimeMillis();
    arr.sortRange(array, Comparator.comparingInt(o -> (int) o), skip, limit);
    long endTime = System.currentTimeMillis();
    System.out.println("Time to sort with Dual Pivot QuickSort is " + (endTime - startTime) + "ms");
  }

  private static void benchmarkSort(Integer[] array) {
    long startTime = System.currentTimeMillis();
    java.util.Arrays.sort(array);
    long endTime = System.currentTimeMillis();
    System.out.println("Time to sort with java.util.Arrays.sort is " + (endTime - startTime) + "ms");
  }

  private static void runBenchmark(int length, int skip, int limit) {
    Integer[] arrayRange = new Integer[length];
    for (int i = 0; i < length; i++) arrayRange[i] = new Random().nextInt();

    Integer[] arrayFull = arrayRange.clone();

    System.out.println();
    System.out.println(String.format("Benchmark #" + count + ".  Number of elements: %,d. Skipped: %,d. Limited: %,d", length, skip, limit));

    benchmarkSort(arrayFull);
    benchmarkQuickSort(arrayRange, skip, limit);
    count++;
  }
}

@@ -301,45 +301,8 @@
 0);%0A
-    runBenchmark(300000, 0, 300000);%0A
     
@@ -347,25 +347,25 @@
 unBenchmark(
-5
+8
 00000, 0, 50
@@ -366,46 +366,9 @@
  0, 
-500000);%0A    runBenchmark(600000, 0, 6
+8
 0000
@@ -639,57 +639,13 @@
  100
-, 1000000);%0A    runBenchmark(2000000, 200, 200000
+00, 2
 0);%0A
@@ -665,17 +665,17 @@
 ark(
-3
+2
 000000, 
 300,
@@ -674,60 +674,16 @@
 00, 
-300, 3000000);%0A    runBenchmark(4000000, 400, 400000
+10000, 2
 0);%0A
@@ -703,69 +703,25 @@
 ark(
-500
+4
 0000
-, 5
 00, 
-5000000);%0A    runBenchmark(6000000, 600, 600000
+10000, 2
 0);%0A
@@ -741,17 +741,17 @@
 ark(
-7
+8
 000000, 
 700,
@@ -750,60 +750,16 @@
 00, 
-700, 7000000);%0A    runBenchmark(8000000, 800, 800000
+10000, 2
 0);%0A

Update QuickSort benchmarks.