Пример #1
0
        public virtual void GlobalSetup()
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;

            FooBar[]                      fooBars                 = new FooBar[this.VectorLength];
            FooBarNonVirtual[]            fooBarsNV               = new FooBarNonVirtual[this.VectorLength];
            FooBar_ValueType[]            fooBarsValue            = new FooBar_ValueType[this.VectorLength];
            FooBar_ValueType_NonVirtual[] fooBarsValue_NonVirtual = new FooBar_ValueType_NonVirtual[this.VectorLength];

            for (int i = 0; i < fooBars.Length; i++)
            {
                var foo = new Foo
                {
                    Id     = 0xABADCAFEABADCAFE + (ulong)i,
                    Count  = (short)(10000 + i),
                    Prefix = (sbyte)('@' + i),
                    Length = (uint)(1000000 + i)
                };

                var fooNV = new FooNonVirtual
                {
                    Id     = 0xABADCAFEABADCAFE + (ulong)i,
                    Count  = (short)(10000 + i),
                    Prefix = (sbyte)('@' + i),
                    Length = (uint)(1000000 + i)
                };

                var fooValue = new Foo_ValueType
                {
                    Id     = 0xABADCAFEABADCAFE + (ulong)i,
                    Count  = (short)(10000 + i),
                    Prefix = (sbyte)('@' + i),
                    Length = (uint)(1000000 + i)
                };

                var bar = new Bar
                {
                    Parent = foo,
                    Ratio  = 3.14159f + i,
                    Size   = (ushort)(10000 + i),
                    Time   = 123456 + i
                };

                var barNV = new BarNonVirtual
                {
                    Parent = fooNV,
                    Ratio  = 3.14159f + i,
                    Size   = (ushort)(10000 + i),
                    Time   = 123456 + i
                };

                var barValue = new Bar_ValueType
                {
                    Parent = fooValue,
                    Ratio  = 3.14159f + i,
                    Size   = (ushort)(10000 + i),
                    Time   = 123456 + i
                };

                var fooBar = new FooBar
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = bar,
                };

                var fooBarNV = new FooBarNonVirtual
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = barNV,
                };

                var fooBarValue = new FooBar_ValueType
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = barValue,
                };

                var fooBarValueNV = new FooBar_ValueType_NonVirtual
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = barValue,
                };

                fooBars[i]                 = fooBar;
                fooBarsNV[i]               = fooBarNV;
                fooBarsValue[i]            = fooBarValue;
                fooBarsValue_NonVirtual[i] = fooBarValueNV;
            }

            this.defaultContainer = new FooBarListContainer
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBars,
            };

            this.defaultContainerNonVirtual = new FooBarListContainerNonVirtual
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBarsNV,
            };

            this.defaultContainerWithValueStructs = new FooBarListContainer_ValueType
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBarsValue,
            };

            this.defaultContainerWithValueStructsNonVirtual = new FooBarListContainer_ValueType_NonVirtual
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBarsValue_NonVirtual,
            };

            Random rng = new Random();

            this.sortedIntContainer = new SortedVectorTable <int> {
                Vector = new List <SortedVectorTableItem <int> >()
            };
            this.sortedStringContainer = new SortedVectorTable <string> {
                Vector = new List <SortedVectorTableItem <string> >()
            };
            this.unsortedIntContainer = new UnsortedVectorTable <int> {
                Vector = new List <UnsortedVectorTableItem <int> >()
            };
            this.unsortedStringContainer = new UnsortedVectorTable <string> {
                Vector = new List <UnsortedVectorTableItem <string> >()
            };

            for (int i = 0; i < this.VectorLength; ++i)
            {
                this.sortedIntContainer.Vector.Add(new SortedVectorTableItem <int> {
                    Key = rng.Next()
                });
                this.sortedStringContainer.Vector.Add(new SortedVectorTableItem <string> {
                    Key = Guid.NewGuid().ToString()
                });
                this.unsortedIntContainer.Vector.Add(new UnsortedVectorTableItem <int> {
                    Key = rng.Next()
                });
                this.unsortedStringContainer.Vector.Add(new UnsortedVectorTableItem <string> {
                    Key = Guid.NewGuid().ToString()
                });
            }

            this.valueTableVector = new ValueTableVector
            {
                ValueTables = Enumerable.Range(0, this.VectorLength).Select(x => new ValueTable
                {
                    A = 1,
                    B = 2,
                    C = 3,
                    D = 4,
                    E = 5,
                    F = 6,
                    G = 7,
                    H = 8,
                    I = 9,
                    J = 10,
                    K = true,
                }).ToArray()
            };

            {
                var options = new FlatBufferSerializerOptions(this.DeserializeOption);

                this.fs_serializer = new FlatBufferSerializer(options);

                int offset = this.fs_serializer.Serialize(this.defaultContainer, this.fs_writeMemory);
                this.fs_readMemory = this.fs_writeMemory.AsSpan(0, offset).ToArray();
                this.inputBuffer   = new InputBufferKind(this.fs_readMemory);
                this.FlatSharp_ParseAndTraverse();
            }

            int googleLength = 0;

            {
                this.google_ByteBuffer       = new FlatBuffers.ByteBuffer(this.fs_readMemory.ToArray());
                this.google_defaultContainer = Google.FooBarContainer.GetRootAsFooBarContainer(this.google_ByteBuffer).UnPack();
                googleLength = this.Google_FlatBuffers_Serialize_ObjectApi();
            }

            {
                this.PBDN_Serialize();
                this.pbdn_writeBuffer.Position = 0;
                this.pbdn_writeBuffer.CopyTo(this.pbdn_readBuffer);
                this.PBDN_ParseAndTraverse();
            }

            {
                this.MsgPack_Serialize_NonVirtual();
            }

            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;

            Console.WriteLine($"Sizes: MsgPack: {this.msgPackWriteData.Length}");
            Console.WriteLine($"Sizes: FlatSharp: {this.fs_readMemory.Length}");
            Console.WriteLine($"Sizes: Google: {googleLength}");
            Console.WriteLine($"Sizes: Pbdn: {this.pbdn_writeBuffer.Length}");
        }
Пример #2
0
        public virtual void GlobalSetup()
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;

            FooBar[]           fooBars   = new FooBar[this.VectorLength];
            FooBarNonVirtual[] fooBarsNV = new FooBarNonVirtual[this.VectorLength];
            for (int i = 0; i < fooBars.Length; i++)
            {
                var foo = new Foo
                {
                    Id     = 0xABADCAFEABADCAFE + (ulong)i,
                    Count  = (short)(10000 + i),
                    Prefix = (sbyte)('@' + i),
                    Length = (uint)(1000000 + i)
                };

                var fooNV = new FooNonVirtual
                {
                    Id     = 0xABADCAFEABADCAFE + (ulong)i,
                    Count  = (short)(10000 + i),
                    Prefix = (sbyte)('@' + i),
                    Length = (uint)(1000000 + i)
                };

                var bar = new Bar
                {
                    Parent = foo,
                    Ratio  = 3.14159f + i,
                    Size   = (ushort)(10000 + i),
                    Time   = 123456 + i
                };

                var barNV = new BarNonVirtual
                {
                    Parent = fooNV,
                    Ratio  = 3.14159f + i,
                    Size   = (ushort)(10000 + i),
                    Time   = 123456 + i
                };

                var fooBar = new FooBar
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = bar,
                };

                var fooBarNV = new FooBarNonVirtual
                {
                    Name    = Guid.NewGuid().ToString(),
                    PostFix = (byte)('!' + i),
                    Rating  = 3.1415432432445543543 + i,
                    Sibling = barNV,
                };

                fooBars[i]   = fooBar;
                fooBarsNV[i] = fooBarNV;
            }

            this.defaultContainer = new FooBarListContainer
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBars,
            };

            this.defaultContainerNonVirtual = new FooBarListContainerNonVirtual
            {
                Fruit       = 123,
                Initialized = true,
                Location    = "http://google.com/flatbuffers/",
                List        = fooBarsNV,
            };

            Random rng = new Random();

            this.sortedIntContainer = new SortedVectorTable <int> {
                Vector = new List <SortedVectorTableItem <int> >()
            };
            this.sortedStringContainer = new SortedVectorTable <string> {
                Vector = new List <SortedVectorTableItem <string> >()
            };
            this.unsortedIntContainer = new UnsortedVectorTable <int> {
                Vector = new List <UnsortedVectorTableItem <int> >()
            };
            this.unsortedStringContainer = new UnsortedVectorTable <string> {
                Vector = new List <UnsortedVectorTableItem <string> >()
            };

            for (int i = 0; i < this.VectorLength; ++i)
            {
                this.sortedIntContainer.Vector.Add(new SortedVectorTableItem <int> {
                    Key = rng.Next()
                });
                this.sortedStringContainer.Vector.Add(new SortedVectorTableItem <string> {
                    Key = Guid.NewGuid().ToString()
                });
                this.unsortedIntContainer.Vector.Add(new UnsortedVectorTableItem <int> {
                    Key = rng.Next()
                });
                this.unsortedStringContainer.Vector.Add(new UnsortedVectorTableItem <string> {
                    Key = Guid.NewGuid().ToString()
                });
            }

            {
                var options = new FlatBufferSerializerOptions(this.DeserializeOption);

                this.fs_serializer = new FlatBufferSerializer(options);

                int offset = this.fs_serializer.Serialize(this.defaultContainer, this.fs_writeMemory);
                this.fs_readMemory = this.fs_writeMemory.AsSpan(0, offset).ToArray();
                this.inputBuffer   = new ArrayInputBuffer(this.fs_readMemory);
                this.FlatSharp_ParseAndTraverse();
            }

            {
                this.google_ByteBuffer       = new FlatBuffers.ByteBuffer(this.fs_readMemory.ToArray());
                this.google_defaultContainer = Google.FooBarContainer.GetRootAsFooBarContainer(this.google_ByteBuffer).UnPack();
            }

            {
                this.PBDN_Serialize();
                this.pbdn_writeBuffer.Position = 0;
                this.pbdn_writeBuffer.CopyTo(this.pbdn_readBuffer);
                this.PBDN_ParseAndTraverse();
            }

            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
        }