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;
 }
Esempio n. 2
0
  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));
    }
  }