public void TestBlocksPerSecond()
        {
            //UnmanagedMemory.Memory.UseLargePages = true;
            DebugStopwatch sw = new DebugStopwatch();

            using (MemoryPoolStream ms = new MemoryPoolStream())
            {
                using (BinaryStreamIoSessionBase io = ms.CreateIoSession())
                {
                    BlockArguments args = new BlockArguments();
                    args.Position  = ms.BlockSize * 2000L - 1;
                    args.IsWriting = true;

                    io.GetBlock(args);

                    double sec = sw.TimeEvent(() =>
                    {
                        for (int y = 0; y < 100; y++)
                        {
                            for (int x = 0; x < 2000; x++)
                            {
                                args.Position = (long)x * ms.BlockSize;
                                io.GetBlock(args);
                            }
                        }
                    });

                    System.Console.WriteLine("Get Blocks: " + (200000 / sec / 1000000).ToString("0.00 Million Per Second"));
                }
            }
        }
        public void TestBlocksPerSecond()
        {
            //UnmanagedMemory.Memory.UseLargePages = true;
            DebugStopwatch sw = new DebugStopwatch();
            using (MemoryPoolStream ms = new MemoryPoolStream())
            {
                using (var io = ms.CreateIoSession())
                {
                    BlockArguments args = new BlockArguments();
                    args.Position = ms.BlockSize * 2000L - 1;
                    args.IsWriting = true;

                    io.GetBlock(args);

                    double sec = sw.TimeEvent(() =>
                        {
                            for (int y = 0; y < 100; y++)
                                for (int x = 0; x < 2000; x++)
                                {
                                    args.Position = (long)x * ms.BlockSize;
                                    io.GetBlock(args);
                                }
                        });

                    System.Console.WriteLine("Get Blocks: " + (200000 / sec / 1000000).ToString("0.00 Million Per Second"));
                }
            }


        }
Beispiel #3
0
        private static void SelfTest()
        {
            MemoryPoolStream ms1  = new MemoryPoolStream();
            BinaryStreamBase ms   = ms1.CreateBinaryStream();
            Random           rand = new Random();
            int seed = rand.Next();

            rand = new Random(seed);
            byte[] data = new byte[255];
            rand.NextBytes(data);

            while (ms.Position < 1000000)
            {
                ms.Write(data, 0, rand.Next(256));
            }

            byte[] data2 = new byte[255];
            rand = new Random(seed);
            rand.NextBytes(data2);
            ms.Position = 0;
            Compare(data, data2, 255);
            while (ms.Position < 1000000)
            {
                int length = rand.Next(256);
                ms.ReadAll(data2, 0, length);
                Compare(data, data2, length);
            }
            ms.Dispose();
            ms1.Dispose();
        }
        private static void SelfTest()
        {
            MemoryPoolStream ms1 = new MemoryPoolStream();
            BinaryStreamBase ms = ms1.CreateBinaryStream();
            Random rand = new Random();
            int seed = rand.Next();
            rand = new Random(seed);
            byte[] data = new byte[255];
            rand.NextBytes(data);

            while (ms.Position < 1000000)
            {
                ms.Write(data, 0, rand.Next(256));
            }

            byte[] data2 = new byte[255];
            rand = new Random(seed);
            rand.NextBytes(data2);
            ms.Position = 0;
            Compare(data, data2, 255);
            while (ms.Position < 1000000)
            {
                int length = rand.Next(256);
                ms.ReadAll(data2, 0, length);
                Compare(data, data2, length);
            }
            ms.Dispose();
            ms1.Dispose();
        }
Beispiel #5
0
        public void RunMemoryStreamTest()
        {
            MemoryPoolTest.TestMemoryLeak();
            MemoryPoolStream ms = new MemoryPoolStream();
            BinaryStream     bs = new BinaryStream(ms);

            Run(bs, false);
            ms.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();

            SelfTest();
            MemoryPoolStream ms = new MemoryPoolStream();
            BinaryStreamTest.Test(ms);
            Assert.IsTrue(true);
            ms.Dispose();

            MemoryPoolTest.TestMemoryLeak();
        }
Beispiel #7
0
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();

            SelfTest();
            MemoryPoolStream ms = new MemoryPoolStream();

            BinaryStreamTest.Test(ms);
            Assert.IsTrue(true);
            ms.Dispose();

            MemoryPoolTest.TestMemoryLeak();
        }
        public void TestReadByte()
        {
            using (var mem = new MemoryPoolStream())
            {
                var buf = new byte[19];
                Array.Fill <byte>(buf, 1);
                mem.Write(buf, 0, buf.Length);

                mem.Position = 0;

                int b = mem.ReadByte();
                Assert.AreEqual(1, b);
            }
        }
Beispiel #9
0
        public async Task <byte[]> ShrinkImage(Uri ImageUri, int pixelSize)
        {
            _logger.LogInformation($"Сжатие изображения до {pixelSize}px");

            using (Bitmap bitmap = await ResizeImageAsync(ImageUri, pixelSize))
            {
                using (var mem = new MemoryPoolStream(4096))
                {
                    BitmapToJpeg(mem, bitmap);
                    byte[] serialized = mem.ToArray();
                    return(serialized);
                }
            }
        }
        public void TestMemoryPoolStream2()
        {
            using (var mem = new MemoryPoolStream())
            {
                for (int i = 0; i < 10; i++)
                {
                    mem.WriteByte(1);
                }
                mem.Position = 0;
                mem.Read(new byte[3], 0, 3);
                mem.Seek(0, SeekOrigin.End);
                mem.Capacity = 20;

                var ar = new byte[10];
                Array.Fill <byte>(ar, 1);
                mem.Write(ar, 0, 10);
            }
        }
        public void TestMemoryPoolStream1()
        {
            var ar = ArrayPool <byte> .Shared.Rent(16);

            Array.Fill <byte>(ar, 1);
            ArrayPool <byte> .Shared.Return(ar);

            using (var mem = new MemoryPoolStream())
            {
                for (int i = 0; i < 10; i++)
                {
                    mem.WriteByte(1);
                }

                // Пропускаем 5 байт.
                mem.Position = 15;

                mem.WriteByte(2);
            }
        }
Beispiel #12
0
 public SendJob(SocketQueue socketQueue, MemoryPoolStream memoryPoolStream)
 {
     SocketQueue      = socketQueue;
     MemoryPoolStream = memoryPoolStream;
 }
Beispiel #13
0
        public void Test()
        {
            MemoryPoolTest.TestMemoryLeak();
            const int        count = 100;
            MemoryPoolStream ms    = new MemoryPoolStream();
            //ms.Write(new byte[100000], 0, 100000);
            //ms.Write(new byte[100000], 0, 100000);
            //ms.Position = 0;
            BinaryStream bs = new BinaryStream(ms);
            Stopwatch    sw = new Stopwatch();
            //DateTime b = DateTime.UtcNow;
            long b = 10;

            //Guid b = Guid.NewGuid() ;
            for (int x2 = 0; x2 < count; x2++)
            {
                bs.Position = 0;
                for (int x = 0; x < count; x++)
                {
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                }
            }

            sw.Start();
            for (int x2 = 0; x2 < count; x2++)
            {
                bs.Position = 0;
                for (int x = 0; x < count; x++)
                {
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    bs.Write(b);
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadDecimal();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt64();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt32();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadInt16();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.ReadByte();
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                    //bs.Write7Bit(b);
                }
            }
            sw.Stop();
            Assert.IsTrue(true);
            ms.Dispose();
            MemoryPoolTest.TestMemoryLeak();
            //MessageBox.Show((count * count * 10 / sw.Elapsed.TotalSeconds / 1000000).ToString());
        }