コード例 #1
0
 public void Decompression()
 {
     Benchmark.Run("Decompressing", 1024 * 1024 * 2, benchmark =>
     {
         var stream       = new RepeaterStream(GetCompressedFile(benchmark.Input));
         var decompressor = new SnappyDOTNETStream(stream, CompressionMode.Decompress);
         var decompressed = new byte[benchmark.Input.Length];
         benchmark.Stopwatch.Start();
         for (int i = 0; i < benchmark.Iterations; ++i)
         {
             ReadFully(decompressor, decompressed, 0, decompressed.Length);
         }
         benchmark.Stopwatch.Stop();
     });
 }
コード例 #2
0
 private void DoUncompressionBenchmark(int size)
 {
     Benchmark.Run("Uncompressing", size, benchmark =>
     {
         var compressed = CompressTool.Compress(benchmark.Input);
         var roundtrip  = new byte[benchmark.Input.Length];
         int length     = 0;
         benchmark.Stopwatch.Start();
         for (int i = 0; i < benchmark.Iterations; ++i)
         {
             length = CompressTool.Uncompress(compressed, 0, compressed.Length, roundtrip, 0);
         }
         benchmark.Stopwatch.Stop();
         CollectionAssert.AreEqual(benchmark.Input, roundtrip);
     });
 }
コード例 #3
0
 public void Compression()
 {
     Benchmark.Run("Compressing", 1024 * 1024 * 2, benchmark =>
     {
         var stream     = new NullStream();
         var compressor = new SnappyDOTNETStream(stream, CompressionMode.Compress);
         benchmark.Stopwatch.Start();
         for (int i = 0; i < benchmark.Iterations; ++i)
         {
             compressor.Write(benchmark.Input, 0, benchmark.Input.Length);
             compressor.Flush();
         }
         benchmark.Stopwatch.Stop();
         benchmark.Note = String.Format(" ({0:0.00 %})", stream.Written / (double)benchmark.Input.Length / benchmark.Iterations);
     });
 }
コード例 #4
0
        private void DoCompressionOneParaBenchmark(int size)
        {
            Benchmark.Run("Compressing", size, benchmark =>
            {
                int length = 0;
                benchmark.Stopwatch.Start();
                for (int i = 0; i < benchmark.Iterations; ++i)
                {
                    var output = CompressTool.Compress(benchmark.Input);
                    length     = output.Length;
                }
                benchmark.Stopwatch.Stop();


                benchmark.Note = String.Format(" ({0:0.00 %})", length / (double)benchmark.Input.Length);
            });
        }
コード例 #5
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);
     });
 }
コード例 #6
0
 private Task DoAsyncUncompressionOneParaBenchmark(int size)
 {
     return(Task.Factory.StartNew(() =>
     {
         Benchmark.Run("Uncompressing", size, benchmark =>
         {
             var compressed = CompressTool.Compress(benchmark.Input);
             var roundtrip = new byte[benchmark.Input.Length];
             int length = 0;
             benchmark.Stopwatch.Start();
             for (int i = 0; i < benchmark.Iterations; ++i)
             {
                 roundtrip = CompressTool.Uncompress(compressed);
                 length = roundtrip.Length;
             }
             benchmark.Stopwatch.Stop();
             CollectionAssert.AreEqual(benchmark.Input, roundtrip);
         });
     }));
 }
コード例 #7
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);
         });
     }));
 }