コード例 #1
0
		private const int MAXIMUM_LENGTH = 1 * 10 * 1024 * 1024; // 10MB

		#endregion

		#region utilities

		private void TestConformance(TimedMethod[] compressors, TimedMethod[] decompressors)
		{
			var provider = new BlockDataProvider(Utilities.GetSilesiaCorpusFolder());

			var r = new Random(0);

			Console.WriteLine("Architecture: {0}bit", IntPtr.Size * 8);

			var total = 0;
			const long limit = 1L * 1024 * 1024 * 1024;
			var last_pct = 0;

			while (total < limit)
			{
				var length = Utilities.RandomLength(r, MAXIMUM_LENGTH);
				var block = provider.GetBytes(length);
				TestData(block, compressors, decompressors);
				total += block.Length;
				var pct = (int)((double)total * 100 / limit);
				if (pct > last_pct)
				{
					Console.WriteLine("{0}%...", pct);
					last_pct = pct;
				}
			}
		}
コード例 #2
0
ファイル: ConformanceTests.cs プロジェクト: nickaceves/lz4net
        public void TestCompressionConformance()
        {
            var provider = new BlockDataProvider(TEST_DATA_FOLDER);

            var r = new Random(0);

            Console.WriteLine("Architecture: {0}bit", IntPtr.Size * 8);

            var compressors = new[] {
                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("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.Decode32(b, 0, b.Length, l)),
            };

            var total = 0;
            const long limit = 1L * 1024 * 1024 * 1024;
            var last_pct = 0;

            while (total < limit)
            {
                var length = RandomLength(r, MAXIMUM_LENGTH);
                var block = provider.GetBytes(length);
                TestData(block, compressors, decompressors);
                total += block.Length;
                var pct = (int)((double)total * 100 / limit);
                if (pct > last_pct)
                {
                    Console.WriteLine("{0}%...", pct);
                    last_pct = pct;
                }
            }

            /*

            The performance results from this test are completely unreliable
            Too much garbage collection and caching.
            So, no need to mislead anyone.

            Console.WriteLine("Compression:");
            foreach (var compressor in compressors)
            {
                Console.WriteLine("  {0}: {1:0.00}MB/s", compressor.Name, compressor.Speed);
            }

            Console.WriteLine("Decompression:");
            foreach (var decompressor in decompressors)
            {
                Console.WriteLine("  {0}: {1:0.00}MB/s", decompressor.Name, decompressor.Speed);
            }
            */
        }
コード例 #3
0
ファイル: StreamTests.cs プロジェクト: manhunterita/lz4net
		// ReSharper disable InconsistentNaming

		private static void DoAction(Action<byte[], Stream> action, bool read)
		{
			var provider = new BlockDataProvider(Utilities.GetSilesiaCorpusFolder());
			var r = new Random(0);

			Console.WriteLine("Architecture: {0}bit", IntPtr.Size*8);
			Console.WriteLine("CodecName: {0}", LZ4Codec.CodecName);

			var fileName = Path.Combine(Path.GetTempPath(), "BlockCompressionStream.dat");

			using (var stream = new LZ4Stream(
				read ? File.OpenRead(fileName) : File.Create(fileName),
				read ? CompressionMode.Decompress : CompressionMode.Compress, true))
			{
				var total = 0;
				const long limit = TOTAL_SIZE;
				var last_pct = 0;

				while (total < limit)
				{
					var length = Utilities.RandomLength(r, CHUNK_SIZE);
					var block = provider.GetBytes(length);
					action(block, stream);
					total += block.Length;
					var pct = (int)((double)total*100/limit);
					if (pct > last_pct)
					{
						Console.WriteLine("{0}%...", pct);
						last_pct = pct;
					}
				}
			}
		}
コード例 #4
0
ファイル: ConformanceTests.cs プロジェクト: nabeshin/lz4net
        private void TestConformance(TimedMethod[] compressors, TimedMethod[] decompressors)
        {
            var provider = new BlockDataProvider(Utilities.TEST_DATA_FOLDER);

            var r = new Random(0);

            Console.WriteLine("Architecture: {0}bit", IntPtr.Size * 8);

            var total = 0;
            const long limit = 1L * 1024 * 1024 * 1024;
            var last_pct = 0;

            while (total < limit)
            {
                var length = Utilities.RandomLength(r, MAXIMUM_LENGTH);
                var block = provider.GetBytes(length);
                TestData(block, compressors, decompressors);
                total += block.Length;
                var pct = (int)((double)total * 100 / limit);
                if (pct > last_pct)
                {
                    Console.WriteLine("{0}%...", pct);
                    last_pct = pct;
                }
            }

            /*

            The performance results from this test are completely unreliable
            Too much garbage collection and caching.
            So, no need to mislead anyone.

            Console.WriteLine("Compression:");
            foreach (var compressor in compressors)
            {
                Console.WriteLine("  {0}: {1:0.00}MB/s", compressor.Name, compressor.Speed);
            }

            Console.WriteLine("Decompression:");
            foreach (var decompressor in decompressors)
            {
                Console.WriteLine("  {0}: {1:0.00}MB/s", decompressor.Name, decompressor.Speed);
            }
            */
        }