private static void Run(string resultsFile, string path, long limit, string codec, string architecture) { var provider = new FileDataProvider(path.Split(';')); TimedMethod compressor; TimedMethod decompressor; var codecCode = SelectCodec(codec, architecture, out compressor, out decompressor); Warmup(compressor, decompressor); long total = 0; var pct = 0; while (total < limit) { var original = provider.GetBytes(); var length = original.Length; var compressed = compressor.Run(original, length); var decompressed = decompressor.Run(compressed, length); AssertEqual(original, decompressed); total += length; var new_pct = (int)(total * 100 / limit); if (new_pct > pct) { Console.WriteLine("{0}%", new_pct); pct = new_pct; } } Console.WriteLine("{0}: {1:0.00} / {2:0.00}", codecCode, compressor.Speed, decompressor.Speed); UpdateResults(resultsFile, codecCode, compressor, decompressor); }
private static void TestPerformance(TimedMethod[] compressors, TimedMethod[] decompressors) { var names = compressors.Select(c => c.Name).ToArray(); foreach (var name in names) { var compressor = compressors.First(c => c.Name == name); var decompressor = decompressors.First(d => d.Name == name); Console.WriteLine("---- {0} ----", name); Warmup(compressor, decompressor); var provider = new FileDataProvider(Utilities.TEST_DATA_FOLDER); long total = 0; const long limit = 1L*1024*1024*1024; var last_pct = 0; while (total < limit) { var block = provider.GetBytes(); TestSpeed(block, compressor, decompressor); total += block.Length; var pct = (int)((double)total*100/limit); if (pct > last_pct) { Console.WriteLine("{0}%...", pct); last_pct = pct; } } GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Thread.Sleep(1000); } Console.WriteLine("---- Results ----"); Console.WriteLine("Architecture: {0}bit", IntPtr.Size*8); Console.WriteLine("Compression:"); foreach (var compressor in compressors) { Console.WriteLine(" {0}: {1:0.00}MB/s ({2:0.00}%)", compressor.Name, compressor.Speed, compressor.Ratio); } Console.WriteLine("Decompression:"); foreach (var decompressor in decompressors) { Console.WriteLine(" {0}: {1:0.00}MB/s", decompressor.Name, decompressor.Speed); } }
public void TestCompressionPerformance() { var compressors = new[] { new TimedMethod("Copy", Copy), new TimedMethod("MixedMode 64", (b, l) => LZ4mm.LZ4Codec.Encode64(b, 0, l)), new TimedMethod("MixedMode 32", (b, l) => LZ4mm.LZ4Codec.Encode32(b, 0, l)), new TimedMethod("C++/CLI 64", (b, l) => LZ4cc.LZ4Codec.Encode64(b, 0, l)), new TimedMethod("C++/CLI 32", (b, l) => LZ4cc.LZ4Codec.Encode32(b, 0, l)), new TimedMethod("Unsafe 64", (b, l) => LZ4n.LZ4Codec.Encode64(b, 0, l)), new TimedMethod("Unsafe 32", (b, l) => LZ4n.LZ4Codec.Encode32(b, 0, l)), new TimedMethod("Safe 64", (b, l) => LZ4s.LZ4Codec.Encode64(b, 0, l)), new TimedMethod("Safe 32", (b, l) => LZ4s.LZ4Codec.Encode32(b, 0, l)), }; var decompressors = new[] { new TimedMethod("Copy", Copy), new TimedMethod("MixedMode 64", (b, l) => LZ4mm.LZ4Codec.Decode64(b, 0, b.Length, l)), new TimedMethod("MixedMode 32", (b, l) => LZ4mm.LZ4Codec.Decode32(b, 0, b.Length, l)), new TimedMethod("C++/CLI 64", (b, l) => LZ4cc.LZ4Codec.Decode64(b, 0, b.Length, l)), new TimedMethod("C++/CLI 32", (b, l) => LZ4cc.LZ4Codec.Decode32(b, 0, b.Length, l)), new TimedMethod("Unsafe 64", (b, l) => LZ4n.LZ4Codec.Decode64(b, 0, b.Length, l)), new TimedMethod("Unsafe 32", (b, l) => LZ4n.LZ4Codec.Decode32(b, 0, b.Length, l)), new TimedMethod("Safe 64", (b, l) => LZ4s.LZ4Codec.Decode64(b, 0, b.Length, l)), new TimedMethod("Safe 32", (b, l) => LZ4s.LZ4Codec.Decode64(b, 0, b.Length, l)), }; var names = compressors.Select(c => c.Name).ToArray(); foreach (var name in names) { var compressor = compressors.First(c => c.Name == name); var decompressor = decompressors.First(d => d.Name == name); Console.WriteLine("---- {0} ----", name); Warmup(compressor, decompressor); var provider = new FileDataProvider(TEST_DATA_FOLDER); long total = 0; const long limit = 1L * 1024 * 1024 * 1024; var last_pct = 0; while (total < limit) { var block = provider.GetBytes(); TestSpeed(block, compressor, decompressor); total += block.Length; var pct = (int)((double)total * 100 / limit); if (pct > last_pct) { Console.WriteLine("{0}%...", pct); last_pct = pct; } } GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Thread.Sleep(1000); } Console.WriteLine("---- Results ----"); Console.WriteLine("Architecture: {0}bit", IntPtr.Size * 8); Console.WriteLine("Compression:"); foreach (var compressor in compressors) { Console.WriteLine(" {0}: {1:0.00}MB/s ({2:0.00}%)", compressor.Name, compressor.Speed, compressor.Ratio); } Console.WriteLine("Decompression:"); foreach (var decompressor in decompressors) { Console.WriteLine(" {0}: {1:0.00}MB/s", decompressor.Name, decompressor.Speed); } }