public Task FromStreamAsync(int iteration)
    {
        var jilStreamAsync            = JilHelper.ToStream(_testModel);
        var messagePackStreamAsync    = MessagePackHelper.ToStream(_testModel);
        var msgPackStreamAsync        = MsgPackHelper.ToStream(_testModel);
        var newtonsoftJsonStreamAsync = NewtonsoftJsonHelper.ToStream(_testModel);
        var systemTextJsonStreamAsync = SystemTextJsonHelper.ToStream(_testModel);
        var utf8JsonStreamAsync       = Utf8JsonHelper.ToStream(_testModel);

        Console.WriteLine("FromStreamAsync go!");

        Runner.Initialize();

        Console.WriteLine(Runner.Time("JilHelper FromStreamAsync", iteration,
                                      async() => await JilHelper.FromStreamAsync <TestModel>(jilStreamAsync)));
        Console.WriteLine(Runner.Time("MessagePackHelper FromStreamAsync", iteration,
                                      async() => await MessagePackHelper.FromStreamAsync <TestModel>(messagePackStreamAsync)));
        Console.WriteLine(Runner.Time("MsgPackHelper FromStreamAsync", iteration,
                                      async() => await MsgPackHelper.FromStreamAsync <TestModel>(msgPackStreamAsync)));
        Console.WriteLine(Runner.Time("NewtonsoftJsonHelper FromStreamAsync", iteration,
                                      async() => await NewtonsoftJsonHelper.FromStreamAsync <TestModel>(newtonsoftJsonStreamAsync)));
        Console.WriteLine(Runner.Time("SystemTextJsonHelper FromStreamAsync", iteration,
                                      async() => await SystemTextJsonHelper.FromStreamAsync <TestModel>(systemTextJsonStreamAsync)));
        Console.WriteLine(Runner.Time("Utf8JsonHelper FromStreamAsync", iteration,
                                      async() => await Utf8JsonHelper.FromStreamAsync <TestModel>(utf8JsonStreamAsync)));

        Console.WriteLine("\r\nFromStreamAsync complete!\r\n");

        return(Task.CompletedTask);
    }
Exemplo n.º 2
0
    public void FromStream(int iteration)
    {
#pragma warning disable CS0618
        var binaryStream = BinaryHelper.ToStream(_testModel);
#pragma warning restore CS0618
        var dataContractStream   = DataContractHelper.ToStream(_testModel);
        var jilStream            = JilHelper.ToStream(_testModel);
        var messagePackStream    = MessagePackHelper.ToStream(_testModel);
        var msgPackStream        = MsgPackHelper.ToStream(_testModel);
        var newtonsoftJsonStream = NewtonsoftJsonHelper.ToStream(_testModel);
        var protobufStream       = ProtobufHelper.ToStream(_testModel);
        var sharpYamlStream      = SharpYamlHelper.ToStream(_testModel);
        var systemTextJsonStream = SystemTextJsonHelper.ToStream(_testModel);
        var utf8JsonStream       = Utf8JsonHelper.ToStream(_testModel);
        var xmlStream            = XmlHelper.ToStream(_testModel);
        var yamlDotNetStream     = YamlDotNetHelper.ToStream(_testModel);
        var zeroFormatterStream  = ZeroFormatterHelper.ToStream(_testModel);

        Console.WriteLine("FromStream go!");

        Runner.Initialize();

        Console.WriteLine(Runner.Time("BinaryHelper FromStream", iteration,
#pragma warning disable CS0618
                                      () => BinaryHelper.FromStream <TestModel>(binaryStream)));
#pragma warning restore CS0618
        Console.WriteLine(Runner.Time("DataContractHelper FromStream", iteration,
                                      () => DataContractHelper.FromStream <TestModel>(dataContractStream)));
        Console.WriteLine(Runner.Time("JilHelper FromStream", iteration,
                                      () => JilHelper.FromStream <TestModel>(jilStream)));
        Console.WriteLine(Runner.Time("MessagePackHelper FromStream", iteration,
                                      () => MessagePackHelper.FromStream <TestModel>(messagePackStream)));
        Console.WriteLine(Runner.Time("MsgPackHelper FromStream", iteration,
                                      () => MsgPackHelper.FromStream <TestModel>(msgPackStream)));
        Console.WriteLine(Runner.Time("NewtonsoftJsonHelper FromStream", iteration,
                                      () => NewtonsoftJsonHelper.FromStream <TestModel>(newtonsoftJsonStream)));
        Console.WriteLine(Runner.Time("ProtobufHelper FromStream", iteration,
                                      () => ProtobufHelper.FromStream <TestModel>(protobufStream)));
        Console.WriteLine(Runner.Time("SharpYamlHelper FromStream", iteration,
                                      () => SharpYamlHelper.FromStream <TestModel>(sharpYamlStream)));
        Console.WriteLine(Runner.Time("SystemTextJsonHelper FromStream", iteration,
                                      () => SystemTextJsonHelper.FromStream <TestModel>(systemTextJsonStream)));
        Console.WriteLine(Runner.Time("Utf8JsonHelper FromStream", iteration,
                                      () => Utf8JsonHelper.FromStream <TestModel>(utf8JsonStream)));
        Console.WriteLine(Runner.Time("XmlHelper FromStream", iteration,
                                      () => XmlHelper.FromStream <TestModel>(xmlStream)));
        Console.WriteLine(Runner.Time("YamlDotNetHelper FromStream", iteration,
                                      () => YamlDotNetHelper.FromStream <TestModel>(yamlDotNetStream)));
        Console.WriteLine(Runner.Time("ZeroFormatterHelper FromStream", iteration,
                                      () => ZeroFormatterHelper.FromStream <TestModel>(zeroFormatterStream)));

        Console.WriteLine("\r\nFromStream complete!\r\n");
    }
Exemplo n.º 3
0
    public void ToStream(int iteration)
    {
        Console.WriteLine("ToStream go!");

        Runner.Initialize();

        Console.WriteLine(Runner.Time("BinaryHelper ToStream", iteration,
#pragma warning disable CS0618
                                      () => BinaryHelper.ToStream(_testModel)));
#pragma warning restore CS0618
        Console.WriteLine(Runner.Time("DataContractHelper ToStream", iteration,
                                      () => DataContractHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("JilHelper ToStream", iteration,
                                      () => JilHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("MessagePackHelper ToStream", iteration,
                                      () => MessagePackHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("MsgPackHelper ToStream", iteration,
                                      () => MsgPackHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("NewtonsoftJsonHelper ToStream", iteration,
                                      () => NewtonsoftJsonHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("ProtobufHelper ToStream", iteration,
                                      () => ProtobufHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("SharpYamlHelper ToStream", iteration,
                                      () => SharpYamlHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("SystemTextJsonHelper ToStream", iteration,
                                      () => SystemTextJsonHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("Utf8JsonHelper ToStream", iteration,
                                      () => Utf8JsonHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("XmlHelper ToStream", iteration,
                                      () => XmlHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("YamlDotNetHelper ToStream", iteration,
                                      () => YamlDotNetHelper.ToStream(_testModel)));
        Console.WriteLine(Runner.Time("ZeroFormatterHelper ToStream", iteration,
                                      () => ZeroFormatterHelper.ToStream(_testModel)));

        Console.WriteLine("\r\nToStream complete!\r\n");
    }
Exemplo n.º 4
0
 public static MemoryStream ToStream(this object?value, Type type, JsonSerializerOptions?options = null) =>
 SystemTextJsonHelper.ToStream(type, value, options);
Exemplo n.º 5
0
 public static MemoryStream ToStream <TValue>(this TValue?value, JsonSerializerOptions?options = null) =>
 SystemTextJsonHelper.ToStream(value, options);