private static void checkArray(
     int[] expected, int[] actualArray, int actualLen, IntegerCODEC codec) {
   if (actualLen != expected.length) {
     throw new RuntimeException(
         "Length mismatch:"
             + " expected="
             + expected.length
             + " actual="
             + actualLen
             + " codec="
             + codec.toString());
   }
   for (int i = 0; i < expected.length; ++i) {
     if (actualArray[i] != expected[i]) {
       throw new RuntimeException(
           "Value mismatch: "
               + " where="
               + i
               + " expected="
               + expected[i]
               + " actual="
               + actualArray[i]
               + " codec="
               + codec.toString());
     }
   }
 }
 private static void benchmark(
     final PrintWriter csvWriter,
     final String dataName,
     final IntegerCODEC[] codecs,
     final int[][] data,
     final int repeat,
     final int warmup) {
   System.out.println("Processing: " + dataName);
   for (IntegerCODEC codec : codecs) {
     String codecName = codec.toString();
     for (int i = 0; i < warmup; ++i) {
       benchmark(null, null, null, codec, data, repeat);
     }
     benchmark(csvWriter, dataName, codecName, codec, data, repeat);
   }
 }
  private static void bench(ArrayList<int[]> postings, CompressionMode cm, boolean verbose) {
    int maxlength = 0;
    for (int[] x : postings) if (maxlength < x.length) maxlength = x.length;
    if (verbose) System.out.println("Max array length: " + maxlength);
    int[] compbuffer = new int[2 * maxlength + 1024];
    int[] decompbuffer = new int[maxlength];
    if (verbose) System.out.println("Scheme -- bits/int -- speed (mis)");
    for (IntegerCODEC c : (cm == CompressionMode.DELTA ? codecs : regcodecs)) {
      long bef = 0;
      long aft = 0;
      long decomptime = 0;
      long volumein = 0;
      long volumeout = 0;
      int[][] compdata = new int[postings.size()][];
      for (int k = 0; k < postings.size(); ++k) {
        int[] in = postings.get(k);
        IntWrapper inpos = new IntWrapper(0);
        IntWrapper outpos = new IntWrapper(0);
        c.compress(in, inpos, in.length, compbuffer, outpos);
        int clength = outpos.get();
        inpos = new IntWrapper(0);
        outpos = new IntWrapper(0);
        c.uncompress(compbuffer, inpos, clength, decompbuffer, outpos);
        volumein += in.length;
        volumeout += clength;

        if (outpos.get() != in.length) throw new RuntimeException("bug");
        for (int z = 0; z < in.length; ++z)
          if (in[z] != decompbuffer[z]) throw new RuntimeException("bug");
        compdata[k] = Arrays.copyOf(compbuffer, clength);
      }
      bef = System.nanoTime();
      for (int[] cin : compdata) {
        IntWrapper inpos = new IntWrapper(0);
        IntWrapper outpos = new IntWrapper(0);
        c.uncompress(cin, inpos, cin.length, decompbuffer, outpos);
        if (inpos.get() != cin.length) throw new RuntimeException("bug");
      }
      aft = System.nanoTime();
      decomptime += (aft - bef);
      double bitsPerInt = volumeout * 32.0 / volumein;
      double decompressSpeed = volumein * 1000.0 / (decomptime);
      if (verbose)
        System.out.println(
            c.toString() + "\t" + String.format("\t%1$.2f\t%2$.2f", bitsPerInt, decompressSpeed));
    }
  }
 private static int decompress(
     PerformanceLogger logger, IntegerCODEC codec, int[] src, int srcLen, int[] dst) {
   IntWrapper inpos = new IntWrapper();
   IntWrapper outpos = new IntWrapper();
   logger.decompressionTimer.start();
   codec.uncompress(src, inpos, srcLen, dst, outpos);
   logger.decompressionTimer.end();
   return outpos.get();
 }
 private static int compress(PerformanceLogger logger, IntegerCODEC codec, int[] src, int[] dst) {
   IntWrapper inpos = new IntWrapper();
   IntWrapper outpos = new IntWrapper();
   logger.compressionTimer.start();
   codec.compress(src, inpos, src.length, dst, outpos);
   logger.compressionTimer.end();
   int outSize = outpos.get();
   logger.addOriginalSize(src.length);
   logger.addCompressedSize(outSize);
   return outSize;
 }