コード例 #1
0
        public void CouldShuffleUnshuffle()
        {
            byte itemSize = 16;
            var  srcLen   = ItemCount * itemSize;

            var originalPtr     = (byte *)Marshal.AllocHGlobal(srcLen);
            var compressedPtr   = (byte *)Marshal.AllocHGlobal(srcLen);
            var decompressedPtr = (byte *)Marshal.AllocHGlobal(srcLen);

            for (int i = 0; i < ItemCount; i++)
            {
                for (int j = 0; j < itemSize; j++)
                {
                    originalPtr[i * itemSize + j] = (byte)(j + 1);
                }
            }

            var iterations = Iterations;

            var rounds = 3;

            for (int r = 0; r < rounds; r++)
            {
                using (Benchmark.Run("Shuffle", iterations * srcLen))
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        Compression.shuffle((IntPtr)itemSize, (IntPtr)srcLen, originalPtr, compressedPtr);
                    }
                }
                using (Benchmark.Run("Unshuffle", iterations * srcLen))
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        Compression.unshuffle((IntPtr)itemSize, (IntPtr)srcLen, compressedPtr, decompressedPtr);
                    }
                }
            }
            Benchmark.Dump();

            Assert.IsTrue(new Span <byte>(originalPtr, srcLen).SequenceEqual(new Span <byte>(decompressedPtr, srcLen)));
        }
コード例 #2
0
        public void CpuNumberPerformance()
        {
            var count = 10_000_000;

            for (int r = 0; r < 10; r++)
            {
                using (Benchmark.Run(".NET Core", count, true))
                {
                    GetCupuNumberDotnet(count);
                }

                using (Benchmark.Run("Spreads.Native", count, true))
                {
                    GetCupuNumberSpreads(count);
                }

                using (Benchmark.Run("Spreads.Pal", count, true))
                {
                    GetCupuNumberSpreadsPal(count);
                }
            }

            Benchmark.Dump();
        }
コード例 #3
0
        public void Lz4Benchmark()
        {
            const string name  = "LZ4";
            var          count = ItemCount;

            var bufferLen       = count * Unsafe.SizeOf <TestValue>();
            var originalPtr     = (byte *)Marshal.AllocHGlobal(bufferLen);
            var compressedPtr   = (byte *)Marshal.AllocHGlobal(bufferLen * 2);
            var decompressedPtr = (byte *)Marshal.AllocHGlobal(bufferLen);

            for (int i = 0; i < count; i++)
            {
                ((TestValue *)originalPtr)[i] = new TestValue()
                {
                    //Dbl = (double)i + 1 / (double)(i + 1),
                    //Dbl1 = (double)i + 1 / (double)(i + 1),
                    Num  = i,
                    Num1 = i,
                };
            }

            for (int level = 1; level < 10; level++)
            {
                var compressedLen = Compression.compress_lz4(originalPtr, (IntPtr)bufferLen, compressedPtr,
                                                             (IntPtr)(bufferLen * 2), level);

                var decompressedLen = Compression.decompress_lz4(compressedPtr, (IntPtr)compressedLen, decompressedPtr, (IntPtr)bufferLen);

                Console.WriteLine($"{name} Level: {level}, ratio: {1.0 * decompressedLen / compressedLen}");

                Assert.AreEqual(bufferLen, decompressedLen);
                Assert.IsTrue(new Span <byte>(originalPtr, bufferLen).SequenceEqual(new Span <byte>(decompressedPtr, bufferLen)));
            }

            Console.WriteLine("-------------------------------");

            var rounds     = 3;
            var iterations = Iterations / 10;

            for (int r = 0; r < rounds; r++)
            {
                for (int level = 1; level < 10; level++)
                {
                    int compressedLen = 0;
                    using (Benchmark.Run($"{name} W{level}", bufferLen * iterations, true))
                    {
                        for (int i = 0; i < iterations; i++)
                        {
                            compressedLen = Compression.compress_lz4(originalPtr, (IntPtr)bufferLen, compressedPtr,
                                                                     (IntPtr)bufferLen, level);
                        }
                    }

                    using (Benchmark.Run($"{name} R{level}", bufferLen * iterations, true))
                    {
                        for (int i = 0; i < iterations; i++)
                        {
                            Compression.decompress_lz4(compressedPtr, (IntPtr)compressedLen, decompressedPtr, (IntPtr)bufferLen);
                        }
                    }
                }
            }

            Benchmark.Dump();
        }