<commit_before>﻿using System;
using System.Collections.Generic;
using Bond.IO.Safe;
using Bond.Protocols;
using PoliceRecord = Bond.PerformanceTest.Bond.PoliceRecord;

namespace Bond.PerformanceTest
{
    class Program
    {
        private const int Times = 1000000;

        private const int WarmUp = 100;

        static void Main(string[] args)
        {
            SerializeProtobufPerson();
            DeserializeProtobufPerson();

            SerializeBondPersonCompactly();
            DeserializeBondPersonCompactly();

            SerializeBondPersonQuickly();
            DeserializeBondPersonQuickly();

            Console.ReadLine();
        }

        private static void SerializeBondPersonCompactly()
        {
            var serializer = new Serializer<CompactBinaryWriter<OutputBuffer>>(typeof (Bond.Person));

            Action serialize = () =>
            {
                var p = CreateBondPerson();

                var output = new OutputBuffer();
                var writer = new CompactBinaryWriter<OutputBuffer>(output);
                serializer.Serialize(p, writer);
            };

            var timeSpan = serialize.Call(Times, WarmUp).Average();

            Console.WriteLine("Person: Bond compact time - " + timeSpan);
            Console.WriteLine("Person: Bond compact size -" + CreateBondPerson().CompactBondSize());
            Console.WriteLine();
        }

        private static void DeserializeBondPersonCompactly()
        {
            var output = new OutputBuffer();
            var writer = new CompactBinaryWriter<OutputBuffer>(output);
            Serialize.To(writer, CreateBondPerson());

            var deserializer = new Deserializer<CompactBinaryReader<InputBuffer>>(typeof(Bond.Person));

            Action deserialize = () =>
            {
                var input = new InputBuffer(output.Data);
                var reader = new CompactBinaryReader<InputBuffer>(input);
                deserializer.Deserialize<Bond.Person>(reader);
            };

            var average = deserialize.Call(Times, WarmUp).Average();
            Console.WriteLine("Bond cpmpact deserialization time - " + average);
            Console.WriteLine();
        }


        private static void SerializeBondPersonQuickly()
        {
            var serializer = new Serializer<FastBinaryWriter<OutputBuffer>>(typeof(Bond.Person));

            Action serialize = () =>
            {
                var person = CreateBondPerson();

                var output = new OutputBuffer();
                var writer = new FastBinaryWriter<OutputBuffer>(output);
                serializer.Serialize(person, writer);
            };

            var average = serialize.Call(Times, WarmUp).Average();

            Console.WriteLine("Bond fast serialization time - " + average);
            Console.WriteLine("Bond fast output size - " + CreateBondPerson().FastBondSize());
            Console.WriteLine();
        }

        private static void DeserializeBondPersonQuickly()
        {
            var output = new OutputBuffer();
            var writer = new FastBinaryWriter<OutputBuffer>(output);
            Serialize.To(writer, CreateBondPerson());

            var deserializer = new Deserializer<FastBinaryReader<InputBuffer>>(typeof(Bond.Person));<commit_msg>Set the size of the preallocated output buffer<commit_after>﻿using System;
using System.Collections.Generic;
using Bond.IO.Safe;
using Bond.Protocols;
using PoliceRecord = Bond.PerformanceTest.Bond.PoliceRecord;

namespace Bond.PerformanceTest
{
    class Program
    {
        private const int Times = 1000000;

        private const int WarmUp = 100;

        static void Main(string[] args)
        {
            SerializeProtobufPerson();
            DeserializeProtobufPerson();

            SerializeBondPersonCompactly();
            DeserializeBondPersonCompactly();

            SerializeBondPersonQuickly();
            DeserializeBondPersonQuickly();

            Console.ReadLine();
        }

        private static void SerializeBondPersonCompactly()
        {
            var serializer = new Serializer<CompactBinaryWriter<OutputBuffer>>(typeof (Bond.Person));

            Action serialize = () =>
            {
                var p = CreateBondPerson();

                var output = new OutputBuffer(256);
                var writer = new CompactBinaryWriter<OutputBuffer>(output);
                serializer.Serialize(p, writer);
            };

            var timeSpan = serialize.Call(Times, WarmUp).Average();

            Console.WriteLine("Person: Bond compact time - " + timeSpan);
            Console.WriteLine("Person: Bond compact size -" + CreateBondPerson().CompactBondSize());
            Console.WriteLine();
        }

        private static void DeserializeBondPersonCompactly()
        {
            var output = new OutputBuffer();
            var writer = new CompactBinaryWriter<OutputBuffer>(output);
            Serialize.To(writer, CreateBondPerson());

            var deserializer = new Deserializer<CompactBinaryReader<InputBuffer>>(typeof(Bond.Person));

            Action deserialize = () =>
            {
                var input = new InputBuffer(output.Data);
                var reader = new CompactBinaryReader<InputBuffer>(input);
                deserializer.Deserialize<Bond.Person>(reader);
            };

            var average = deserialize.Call(Times, WarmUp).Average();
            Console.WriteLine("Bond cpmpact deserialization time - " + average);
            Console.WriteLine();
        }


        private static void SerializeBondPersonQuickly()
        {
            var serializer = new Serializer<FastBinaryWriter<OutputBuffer>>(typeof(Bond.Person));

            Action serialize = () =>
            {
                var person = CreateBondPerson();

                var output = new OutputBuffer(256);
                var writer = new FastBinaryWriter<OutputBuffer>(output);
                serializer.Serialize(person, writer);
            };

            var average = serialize.Call(Times, WarmUp).Average();

            Console.WriteLine("Bond fast serialization time - " + average);
            Console.WriteLine("Bond fast output size - " + CreateBondPerson().FastBondSize());
            Console.WriteLine();
        }

        private static void DeserializeBondPersonQuickly()
        {
            var output = new OutputBuffer();
            var writer = new FastBinaryWriter<OutputBuffer>(output);
            Serialize.To(writer, CreateBondPerson());

            var deserializer = new Deserializer<FastBinaryReader<InputBuffer>>(typeof(Bond.Person));
{'fraction_non_alphanumeric': 0.0952953554787314, 'fraction_numerical': 0.003908011423418007, 'mean_word_length': 2.1505681818181817, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2951679', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1561, 'n_words': 346}