/// <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); }
/// <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; }
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]); } } }
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]); } }
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); } }
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); } }
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); } } }
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); } } }
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); } }
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); } } }
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); }
/// <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; }
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); } } }
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); } } }
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); } } }
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); } }