Пример #1
0
        public FooBarContainerT UnPack()
        {
            var _o = new FooBarContainerT();

            this.UnPackTo(_o);
            return(_o);
        }
Пример #2
0
 public void UnPackTo(FooBarContainerT _o)
 {
     _o.List = new List <Benchmark.FBBench.Google.FooBarT>();
     for (var _j = 0; _j < this.ListLength; ++_j)
     {
         _o.List.Add(this.List(_j).HasValue ? this.List(_j).Value.UnPack() : null);
     }
     _o.Initialized = this.Initialized;
     _o.Fruit       = this.Fruit;
     _o.Location    = this.Location;
 }
Пример #3
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}");
        }
Пример #4
0
        public virtual void GlobalSetup()
        {
            FooBar[] fooBars = new FooBar[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 bar = new Bar
                {
                    Parent = foo,
                    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,
                };

                fooBars[i] = fooBar;
            }

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

            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();
            }
        }
Пример #5
0
        public static Offset <Benchmark.FBBench.Google.FooBarContainer> Pack(FlatBufferBuilder builder, FooBarContainerT _o)
        {
            if (_o == null)
            {
                return(default(Offset <Benchmark.FBBench.Google.FooBarContainer>));
            }
            var _list = default(VectorOffset);

            if (_o.List != null)
            {
                var __list = new Offset <Benchmark.FBBench.Google.FooBar> [_o.List.Count];
                for (var _j = 0; _j < __list.Length; ++_j)
                {
                    __list[_j] = Benchmark.FBBench.Google.FooBar.Pack(builder, _o.List[_j]);
                }
                _list = CreateListVector(builder, __list);
            }
            var _location = _o.Location == null ? default(StringOffset) : builder.CreateString(_o.Location);

            return(CreateFooBarContainer(
                       builder,
                       _list,
                       _o.Initialized,
                       _o.Fruit,
                       _location));
        }