package org.minperf;

import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

/**
 * A helper class to produce data of the RecSplit paper.
 */
public class Paper {

    public static void main(String... args) {

        // B Generation Time Versus Space
        // RandomizedTest.printEvaluationAndGenerationTimeVersusSpace();
        // RandomizedTest.printTimeVersusSpace();
        // RandomizedTest.printTimeVersusSpace();
        BitCodes.verifyRiceParameterFormula();

        // RandomizedTest.printTimeVersusSpace();
        // RandomizedTest.printGenerationTimeVersusSpace();

        // does not always work (performance depends on the hardware):
        // 4.1 Parameters
        RandomizedTest.verifyParameters();

        simpleTest();

        // 4.3 Split Rule
        SettingsTest.printSplitRule();
        // 4.4 Data Format
        BitCodes.printPositiveMapping();
        Graphics.generateSampleTikz();
        // 4.7 Probabilities
        Probability.veryLargeBucketProbability();
        Probability.asymmetricCase();
        // 4.8 Rice
        BitCodes.printRiceExamples();
        BitCodes.printEliasDeltaExample();
        // 4.9 Space Usage and Generation Time
        TimeAndSpaceEstimator.spaceUsageEstimateSmallSet();
        TimeAndSpaceEstimator.spaceUsageEstimate();
        // 5.2 Time and Space Complexity of Evaluation
        TimeAndSpaceEstimator.listMaxRecursionDepth();
        // 6.1 Reasonable Parameter Values
        RandomizedTest.reasonableParameterValues();
        // 6.2 Using Real-World Data
        WikipediaTest.main();

        // A Evaluation Time
        TimeAndSpaceEstimator.listEvalulationTimes();
        RandomizedTest.printTimeVersusSpace();

        // B Generation Time Versus Space
        RandomizedTest.printGenerationTimeVersusSpace();

        // slow:

        // 4.1 Parameters
        TimeAndSpaceEstimator.calcBestSizes();
        RandomizedTest.verifyParametersBestSize();
        // 6 Experimental Results
        RandomizedTest.experimentalResults();

        for (int loadFactor = 64; loadFactor < 1024; loadFactor *= 2) {
            TimeAndSpaceEstimator.printExpectedSpace(8, loadFactor);
        }

        supplementalHashPerfTest();

    }

    private static void simpleTest() {
        for (int i = 8; i < 1000; i *= 2) {
            RandomizedTest.test(2, i, i, true);
        }
        for (int i = 100; i < 10000; i *= 2) {
            RandomizedTest.test(6, 20, i, true);
        }
    }


    private static void supplementalHashPerfTest() {
        final AtomicLong count = new AtomicLong();
        final AtomicLong dummy = new AtomicLong();
          for (int i = 0; i < 8; i++) {
              new Thread() {
                  @Override
                  public void run() {
                      Random r = new Random();
                      long x = r.nextLong();
                      int sum = 0;
                      while (count.get() >= 0) {
                          x += r.nextLong();
                          for (int i = 0; i < 1000; i++) {
                              int h = Settings.supplementalHash(x, i);
                              h = Settings.scaleSmallSize(h, 30);
                              sum += h;
                          }
                          count.incrementAndGet();
                      }
                      dummy.set(sum);
                  }
              }.start();
          }
          try {
              long c0 = count.get();
              Thread.sleep(1000);
              long c2 = count.get();
              count.set(-11111111);
              System.out.println("count: " + c2 + " " + c0);
              Thread.sleep(1000);
          } catch (InterruptedException e) {
              throw new RuntimeException(e);
          }
      }

}

@@ -171,24 +171,25 @@
 ss Paper %7B%0A%0A
+%0A
     public s
@@ -223,16 +223,29 @@
 rgs) %7B%0A%0A
+%0A%0A        ;%0A%0A
         
@@ -405,58 +405,8 @@
 ();%0A
-        // RandomizedTest.printTimeVersusSpace();%0A
     
@@ -1161,39 +1161,32 @@
 on Time%0A        
-TimeAnd
 SpaceEstimator.s
@@ -1214,39 +1214,32 @@
 lSet();%0A        
-TimeAnd
 SpaceEstimator.s
@@ -1314,39 +1314,32 @@
 luation%0A        
-TimeAnd
 SpaceEstimator.l
@@ -1554,39 +1554,32 @@
 on Time%0A        
-TimeAnd
 SpaceEstimator.l
@@ -1793,39 +1793,32 @@
 ameters%0A        
-TimeAnd
 SpaceEstimator.c
@@ -2053,15 +2053,8 @@
     
-TimeAnd
 Spac
@@ -2064,20 +2064,18 @@
 timator.
-prin
+ge
 tExpecte

Split time and space estimation