Esempio n. 1
0
 /// <summary>
 /// Resets this frame to contain compressed data.
 /// </summary>
 /// <param name="data">Input buffer containing uncompressed data that is compressed by this method before being stored in the frame.</param>
 /// <param name="offset">Offset of uncompressed data in the input buffer.</param>
 /// <param name="count">Size of uncompressed data in the input buffer. Maximum data size is 64KB.</param>
 public void SetCompressed(byte[] data, int offset, int count)
 {
     CheckRange(data, offset, count);
     CheckMaxFrameSize(count);
     EnsureBuffer(CompressTool.GetMaxCompressedLength(count));
     BufferUsage = CompressTool.Compress(data, offset, count, Buffer, 0);
     DataLength  = count;
     Checksum    = ComputeMasked(data, offset, count);
     Type        = SnappyFrameType.Compressed;
 }
Esempio n. 2
0
 private void DoCompressionBenchmark(int size)
 {
     Benchmark.Run("Compressing", size, benchmark =>
     {
         var output = new byte[CompressTool.GetMaxCompressedLength(benchmark.Input.Length)];
         int length = 0;
         benchmark.Stopwatch.Start();
         for (int i = 0; i < benchmark.Iterations; ++i)
         {
             length = CompressTool.Compress(benchmark.Input, 0, benchmark.Input.Length, output, 0);
         }
         benchmark.Stopwatch.Stop();
         var roundtrip       = new byte[benchmark.Input.Length];
         var roundtripLength = CompressTool.Uncompress(output, 0, length, roundtrip, 0);
         Assert.IsTrue(benchmark.Input.SequenceEqual(roundtrip.Take(roundtripLength)));
         benchmark.Note = String.Format(" ({0:0.00 %})", length / (double)benchmark.Input.Length);
     });
 }
Esempio n. 3
0
 private Task DoAsyncCompressionOneParaBenchmark(int size)
 {
     return(Task.Factory.StartNew(() =>
     {
         Benchmark.Run("Compressing", size, benchmark =>
         {
             var output = new byte[CompressTool.GetMaxCompressedLength(benchmark.Input.Length)];
             int length = 0;
             benchmark.Stopwatch.Start();
             for (int i = 0; i < benchmark.Iterations; ++i)
             {
                 output = CompressTool.Compress(benchmark.Input);
                 length = output.Length;
             }
             benchmark.Stopwatch.Stop();
             var roundtrip = CompressTool.Uncompress(output);
             Assert.IsTrue(benchmark.Input.SequenceEqual(roundtrip));
             benchmark.Note = String.Format(" ({0:0.00 %})", length / (double)benchmark.Input.Length);
         });
     }));
 }