Ejemplo n.º 1
0
        /// <summary>
        /// Yields an Enumerable list of paths to GZTestData files
        /// </summary>
        public static IEnumerable <object[]> CompressedFiles()
        {
            if (_compressedFiles == null)
            {
                PerfUtils utils = new PerfUtils();
                _compressedFiles = new List <object[]>();
                // Crypto random data
                byte[] bytes = new byte[100000000];
                var    rand  = RandomNumberGenerator.Create();
                rand.GetBytes(bytes);
                string filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                    using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                        zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });

                // Create a compressed file with repeated segments
                bytes    = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
                filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                    using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                        for (int i = 0; i < 1000; i++)
                        {
                            zip.Write(bytes, 0, bytes.Length);
                        }
                _compressedFiles.Add(new object[] { filePath });
            }
            return(_compressedFiles);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Yields an Enumerable list of paths to GZTestData files
        /// </summary>
        public static IEnumerable<object[]> CompressedFiles()
        {
            if (_compressedFiles == null)
            {
                PerfUtils utils = new PerfUtils();
                _compressedFiles = new List<object[]>();
                // Crypto random data
                byte[] bytes = new byte[100000000];
                var rand = RandomNumberGenerator.Create();
                rand.GetBytes(bytes);
                string filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });

                // Create a compressed file with repeated segments
                bytes = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
                filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    for (int i = 0; i < 1000; i++)
                        zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });
            }
            return _compressedFiles;
        }
Ejemplo n.º 3
0
        public void Compress_Canterbury(int innerIterations, string fileName, CompressionLevel compressLevel)
        {
            byte[]    bytes = File.ReadAllBytes(Path.Combine("GZTestData", "Canterbury", fileName));
            PerfUtils utils = new PerfUtils();

            FileStream[] filestreams = new FileStream[innerIterations];
            GZipStream[] gzips       = new GZipStream[innerIterations];
            string[]     paths       = new string[innerIterations];
            foreach (var iteration in Benchmark.Iterations)
            {
                for (int i = 0; i < innerIterations; i++)
                {
                    paths[i]       = utils.GetTestFilePath();
                    filestreams[i] = File.Create(paths[i]);
                }
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        gzips[i] = new GZipStream(filestreams[i], compressLevel);
                        gzips[i].Write(bytes, 0, bytes.Length);
                        gzips[i].Flush();
                        gzips[i].Dispose();
                        filestreams[i].Dispose();
                    }
                for (int i = 0; i < innerIterations; i++)
                {
                    File.Delete(paths[i]);
                }
            }
        }
Ejemplo n.º 4
0
 public void Compress_Canterbury(int innerIterations, string fileName, CompressionLevel compressLevel)
 {
     byte[] bytes = File.ReadAllBytes(Path.Combine("GZTestData", "Canterbury", fileName));
     PerfUtils utils = new PerfUtils();
     FileStream[] filestreams = new FileStream[innerIterations];
     GZipStream[] gzips = new GZipStream[innerIterations];
     string[] paths = new string[innerIterations];
     foreach (var iteration in Benchmark.Iterations)
     {
         for (int i = 0; i < innerIterations; i++)
         {
             paths[i] = utils.GetTestFilePath();
             filestreams[i] = File.Create(paths[i]);
         }
         using (iteration.StartMeasurement())
             for (int i = 0; i < innerIterations; i++)
             {
                 gzips[i] = new GZipStream(filestreams[i], compressLevel);
                 gzips[i].Write(bytes, 0, bytes.Length);
                 gzips[i].Flush();
                 gzips[i].Dispose();
                 filestreams[i].Dispose();
             }
         for (int i = 0; i < innerIterations; i++)
             File.Delete(paths[i]);
     }
 }
Ejemplo n.º 5
0
 public void GetDirectoryName()
 {
     PerfUtils utils = new PerfUtils();
     string testPath = utils.GetTestFilePath();
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 20000; i++)
             {
                 Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
                 Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
                 Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
             }
 }
Ejemplo n.º 6
0
        public void Combine(int innerIterations)
        {
            PerfUtils utils = new PerfUtils();
            string testPath1 = utils.GetTestFilePath();
            string testPath2 = utils.CreateString(10);

            foreach (var iteration in Benchmark.Iterations)
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                    }
        }
Ejemplo n.º 7
0
        public void GetExtension(int innerIterations)
        {
            PerfUtils utils    = new PerfUtils();
            string    testPath = utils.GetTestFilePath();

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        Path.GetExtension(testPath); Path.GetExtension(testPath); Path.GetExtension(testPath);
                        Path.GetExtension(testPath); Path.GetExtension(testPath); Path.GetExtension(testPath);
                        Path.GetExtension(testPath); Path.GetExtension(testPath); Path.GetExtension(testPath);
                    }
            }
        }
Ejemplo n.º 8
0
        public void GetDirectoryName()
        {
            PerfUtils utils    = new PerfUtils();
            string    testPath = utils.GetTestFilePath();

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < 20000; i++)
                    {
                        Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
                        Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
                        Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
                    }
            }
        }
Ejemplo n.º 9
0
        public void Compress(byte[] bytes)
        {
            PerfUtils utils = new PerfUtils();

            foreach (var iteration in Benchmark.Iterations)
            {
                string filePath = utils.GetTestFilePath();
                using (FileStream output = File.Create(filePath))
                    using (DeflateStream zip = new DeflateStream(output, CompressionMode.Compress))
                        using (iteration.StartMeasurement())
                        {
                            zip.Write(bytes, 0, bytes.Length);
                        }
                File.Delete(filePath);
            }
        }
Ejemplo n.º 10
0
        public void Combine(int innerIterations)
        {
            PerfUtils utils     = new PerfUtils();
            string    testPath1 = utils.GetTestFilePath();
            string    testPath2 = utils.CreateString(10);

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                    }
            }
        }
Ejemplo n.º 11
0
        private static string CreateCompressedFile(CompressionType type)
        {
            const int fileSize = 1000000;
            PerfUtils utils    = new PerfUtils();
            string    filePath = utils.GetTestFilePath() + ".gz";

            switch (type)
            {
            case CompressionType.CryptoRandom:
                using (RandomNumberGenerator rand = RandomNumberGenerator.Create())
                {
                    byte[] bytes = new byte[fileSize];
                    rand.GetBytes(bytes);
                    using (FileStream output = File.Create(filePath))
                        using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                            zip.Write(bytes, 0, bytes.Length);
                }
                break;

            case CompressionType.RepeatedSegments:
            {
                byte[] bytes = new byte[fileSize / 1000];
                new Random(128453).NextBytes(bytes);
                using (FileStream output = File.Create(filePath))
                    using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                        for (int i = 0; i < 1000; i++)
                        {
                            zip.Write(bytes, 0, bytes.Length);
                        }
            }
            break;

            case CompressionType.NormalData:
            {
                byte[] bytes = new byte[fileSize];
                new Random(128453).NextBytes(bytes);
                using (FileStream output = File.Create(filePath))
                    using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                        zip.Write(bytes, 0, bytes.Length);
            }
            break;
            }
            return(filePath);
        }
Ejemplo n.º 12
0
 /// <returns></returns>
 private static string CreateCompressedFile(CompressionType type)
 {
     const int fileSize = 100000000;
     PerfUtils utils = new PerfUtils();
     string filePath = utils.GetTestFilePath() + ".gz";
     switch (type)
     {    
         case CompressionType.CryptoRandom:
             using (RandomNumberGenerator rand = RandomNumberGenerator.Create())
             {
                 byte[] bytes = new byte[fileSize];
                 rand.GetBytes(bytes);
                 using (FileStream output = File.Create(filePath))
                 using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                     zip.Write(bytes, 0, bytes.Length);
             }
             break;
         case CompressionType.RepeatedSegments:
             {
                 byte[] bytes = new byte[fileSize / 1000];
                 new Random(128453).NextBytes(bytes);
                 using (FileStream output = File.Create(filePath))
                 using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                     for (int i = 0; i < 1000; i++)
                         zip.Write(bytes, 0, bytes.Length);
             }
             break;
         case CompressionType.NormalData:
             {
                 byte[] bytes = new byte[fileSize];
                 new Random(128453).NextBytes(bytes);
                 using (FileStream output = File.Create(filePath))
                 using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                     zip.Write(bytes, 0, bytes.Length);
             }
             break;
     }
     return filePath;
 }
Ejemplo n.º 13
0
        public void GetDirectoryName()
        {
            PerfUtils utils    = new PerfUtils();
            string    testPath = utils.GetTestFilePath();

            // warmup
            for (int i = 0; i < 100; i++)
            {
                str = Path.GetDirectoryName(testPath);
            }

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath);
                        str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath);
                        str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath); str = Path.GetDirectoryName(testPath);
                    }
            }
        }
Ejemplo n.º 14
0
        public void ChangeExtension()
        {
            PerfUtils utils     = new PerfUtils();
            string    testPath  = utils.GetTestFilePath();
            string    extension = utils.CreateString(4);

            // warmup
            for (int i = 0; i < 100; i++)
            {
                str = Path.ChangeExtension(testPath, extension);
            }

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension);
                        str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension);
                        str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension); str = Path.ChangeExtension(testPath, extension);
                    }
            }
        }
Ejemplo n.º 15
0
        public void Combine()
        {
            PerfUtils utils     = new PerfUtils();
            string    testPath1 = utils.GetTestFilePath();
            string    testPath2 = utils.CreateString(10);

            // warmup
            for (int i = 0; i < 100; i++)
            {
                str = Path.Combine(testPath1, testPath2);
            }

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2);
                        str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2);
                        str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2);
                    }
            }
        }
Ejemplo n.º 16
0
 public void Compress(CompressionType type)
 {
     byte[] bytes = CreateBytesToCompress(type);
     PerfUtils utils = new PerfUtils();
     foreach (var iteration in Benchmark.Iterations)
     {
         string filePath = utils.GetTestFilePath();
         using (FileStream output = File.Create(filePath))
         using (DeflateStream zip = new DeflateStream(output, CompressionMode.Compress))
         using (iteration.StartMeasurement())
         {
             zip.Write(bytes, 0, bytes.Length);
         }
         File.Delete(filePath);
     }
 }