public unsafe void PerformanceTest_PackedBinaryWriter_Write_MockEntities(int count)
        {
            var json = JsonTestData.GetMockEntities(count);

            fixed(char *ptr = json)
            {
                m_Tokenizer.Write(new UnsafeBuffer <char> {
                    Buffer = ptr, Length = json.Length
                }, 0, json.Length);
            }

            Measure.Method(() =>
            {
                using (var stream = new PackedBinaryStream(Allocator.TempJob))
                    using (var writer = new PackedBinaryWriter(stream, m_Tokenizer))
                    {
                        fixed(char *ptr = json)
                        {
                            writer.Write(new UnsafeBuffer <char> {
                                Buffer = ptr, Length = json.Length
                            }, m_Tokenizer.TokenNextIndex);
                        }
                    }
            })
            .Definition("PackedBinaryWriterWrite")
            .WarmupCount(1)
            .MeasurementCount(100)
            .Run();

            PerformanceTest.Active.CalculateStatisticalValues();

            var size = json.Length / (double)1024 / 1024;

            Debug.Log($"MB/s=[{size / (PerformanceTest.Active.SampleGroups.First().Median / 1000)}]");
        }
        public unsafe void PackedBinaryWriter_Write(string json)
        {
            using (var tokenizer = new JsonTokenizer(Allocator.TempJob))
                using (var stream = new PackedBinaryStream(Allocator.TempJob))
                    using (var writer = new PackedBinaryWriter(stream, tokenizer, Allocator.TempJob))
                    {
                        fixed(char *ptr = json)
                        {
                            var buffer = new UnsafeBuffer <char>(ptr, json.Length);

                            tokenizer.Write(buffer, 0, json.Length);
                            writer.Write(buffer, tokenizer.TokenNextIndex);
                        }
                    }
        }
Пример #3
0
        public unsafe void PackedBinaryWriter_Write_PartialKey(params object[] parts)
        {
            using (var tokenizer = new JsonTokenizer(Allocator.TempJob))
                using (var stream = new PackedBinaryStream(Allocator.TempJob))
                    using (var writer = new PackedBinaryWriter(stream, tokenizer))
                    {
                        foreach (string json in parts)
                        {
                            fixed(char *ptr = json)
                            {
                                var buffer = new UnsafeBuffer <char> {
                                    Buffer = ptr, Length = json.Length
                                };

                                tokenizer.Write(buffer, 0, json.Length);
                                writer.Write(buffer, tokenizer.TokenNextIndex);
                            }
                        }

                        stream.DiscardCompleted();
                    }
        }
        public unsafe void PackedBinaryWriter_Write_PartialKey(string input)
        {
            var parts = input.Split('|');

            using (var tokenizer = new JsonTokenizer(Allocator.TempJob))
                using (var stream = new PackedBinaryStream(Allocator.TempJob))
                    using (var writer = new PackedBinaryWriter(stream, tokenizer, Allocator.TempJob))
                    {
                        foreach (var json in parts)
                        {
                            fixed(char *ptr = json)
                            {
                                var buffer = new UnsafeBuffer <char>(ptr, json.Length);

                                tokenizer.Write(buffer, 0, json.Length);
                                writer.Write(buffer, tokenizer.TokenNextIndex);
                            }
                        }

                        stream.DiscardCompleted();
                    }
        }