Ejemplo n.º 1
0
        public void DoTest()
        {
            byte[] buffer = new byte[1000000];

            var rnd = new Random();

            rnd.NextBytes(buffer);

            double    ratio;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            var output = Deflater.Do(buffer);

            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            Console.WriteLine($"origin {buffer.Length} bytes, deflated {output.Length} bytes.");

            watch.Reset();
            watch.Start();
            Deflater.Do(buffer);
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            Console.WriteLine($"origin {buffer.Length} bytes, deflated {output.Length} bytes.");
        }
Ejemplo n.º 2
0
        public void DeflateInflateTest()
        {
            for (int i = 0; i < 1; i++)
            {
                byte[] buffer = new byte[10000000];

                var rnd = new Random();
                rnd.NextBytes(buffer);


                var    deflated = Deflater.Do(buffer);
                var    inflated = Inflater.Do(deflated);
                double ratio    = (double)deflated.Length / buffer.Length;
                Assert.AreEqual(buffer.Length, inflated.Length);

                var    deflated_bzip = BZip2.BZip2.Compress(buffer);
                var    inflated_bzip = BZip2.BZip2.Decompress(deflated_bzip);
                double ratio2        = (double)deflated_bzip.Length / buffer.Length;

                Console.WriteLine($"Base: {ratio}, BZip2: {ratio2}");
            }
        }