Пример #1
0
 @Override
 public void write(byte[] b, int off, int len) {
   CRC.Update(b, off, len);
 }
Пример #2
0
  public static int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception {
    if (numIterations <= 0) return 0;
    if (dictionarySize < (1 << 18)) {
      System.out.println("\nError: dictionary size for benchmark must be >= 18 (256 KB)");
      return 1;
    }
    System.out.print("\n	   Compressing				Decompressing\n\n");

    SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();
    SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();

    if (!encoder.SetDictionarySize(dictionarySize))
      throw new Exception("Incorrect dictionary size");

    int kBufferSize = dictionarySize + kAdditionalSize;
    int kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;

    ByteArrayOutputStream propStream = new ByteArrayOutputStream();
    encoder.WriteCoderProperties(propStream);
    byte[] propArray = propStream.toByteArray();
    decoder.SetDecoderProperties(propArray);

    CBenchRandomGenerator rg = new CBenchRandomGenerator();

    rg.Set(kBufferSize);
    rg.Generate();
    CRC crc = new CRC();
    crc.Init();
    crc.Update(rg.Buffer, 0, rg.BufferSize);

    CProgressInfo progressInfo = new CProgressInfo();
    progressInfo.ApprovedStart = dictionarySize;

    long totalBenchSize = 0;
    long totalEncodeTime = 0;
    long totalDecodeTime = 0;
    long totalCompressedSize = 0;

    MyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);

    byte[] compressedBuffer = new byte[kCompressedBufferSize];
    MyOutputStream compressedStream = new MyOutputStream(compressedBuffer);
    CrcOutStream crcOutStream = new CrcOutStream();
    MyInputStream inputCompressedStream = null;
    int compressedSize = 0;
    for (int i = 0; i < numIterations; i++) {
      progressInfo.Init();
      inStream.reset();
      compressedStream.reset();
      encoder.Code(inStream, compressedStream, -1, -1, progressInfo);
      long encodeTime = System.currentTimeMillis() - progressInfo.Time;

      if (i == 0) {
        compressedSize = compressedStream.size();
        inputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);
      } else if (compressedSize != compressedStream.size()) throw (new Exception("Encoding error"));

      if (progressInfo.InSize == 0) throw (new Exception("Internal ERROR 1282"));

      long decodeTime = 0;
      for (int j = 0; j < 2; j++) {
        inputCompressedStream.reset();
        crcOutStream.Init();

        long outSize = kBufferSize;
        long startTime = System.currentTimeMillis();
        if (!decoder.Code(inputCompressedStream, crcOutStream, outSize))
          throw (new Exception("Decoding Error"));
        decodeTime = System.currentTimeMillis() - startTime;
        if (crcOutStream.GetDigest() != crc.GetDigest()) throw (new Exception("CRC Error"));
      }
      long benchSize = kBufferSize - progressInfo.InSize;
      PrintResults(dictionarySize, encodeTime, benchSize, false, 0);
      System.out.print("	 ");
      PrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);
      System.out.println();

      totalBenchSize += benchSize;
      totalEncodeTime += encodeTime;
      totalDecodeTime += decodeTime;
      totalCompressedSize += compressedSize;
    }
    System.out.println("---------------------------------------------------");
    PrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);
    System.out.print("	 ");
    PrintResults(
        dictionarySize,
        totalDecodeTime,
        kBufferSize * (long) numIterations,
        true,
        totalCompressedSize);
    System.out.println("	Average");
    return 0;
  }
Пример #3
0
 @Override
 public void write(byte[] b) {
   CRC.Update(b);
 }