Change add namespaces and make naming consistent with their file names
Rename of ProtobufSerializer to ProtobufNetSerializer and BinaryFormatter to BinaryFormatterSerializer to have more consistency.
This commit is contained in:
Родитель
7db2ed6231
Коммит
25fe3f9eea
|
@ -31,19 +31,19 @@ namespace Benchmark
|
|||
new MsgPack_v2_opt(),
|
||||
//new MsgPack_v2_string(),
|
||||
//new MsgPack_v2_str_lz4(),
|
||||
new ProtobufNet(),
|
||||
new JsonNet(),
|
||||
new BsonNet(),
|
||||
new BinaryFormatter_(),
|
||||
new DataContract_(),
|
||||
new Hyperion_(),
|
||||
new Jil_(),
|
||||
new SpanJson_(),
|
||||
new Utf8Json_(),
|
||||
new SystemTextJson(),
|
||||
new MsgPackCli(),
|
||||
new FsPickler_(),
|
||||
new Ceras_(),
|
||||
new ProtobufNetSerializer(),
|
||||
new JsonNetSerializer(),
|
||||
new BsonNetSerializer(),
|
||||
new BinaryFormatterSerializer(),
|
||||
new DataContractSerializer(),
|
||||
new HyperionSerializer(),
|
||||
new JilSerializer(),
|
||||
new SpanJsonSerializer(),
|
||||
new Utf8JsonSerializer(),
|
||||
new SystemTextJsonSerializer(),
|
||||
new MsgPackCliSerializer(),
|
||||
new FsPicklerSerializer(),
|
||||
new CerasSerializer(),
|
||||
};
|
||||
|
||||
protected static readonly ExpressionTreeFixture ExpressionTreeFixture = new ExpressionTreeFixture();
|
||||
|
@ -1111,19 +1111,19 @@ namespace Benchmark
|
|||
new MsgPack_v2_string(),
|
||||
new MsgPack_v1_str_lz4(),
|
||||
new MsgPack_v2_str_lz4(),
|
||||
new ProtobufNet(),
|
||||
new JsonNet(),
|
||||
new BsonNet(),
|
||||
new BinaryFormatter_(),
|
||||
new DataContract_(),
|
||||
new Hyperion_(),
|
||||
new Jil_(),
|
||||
new SpanJson_(),
|
||||
new Utf8Json_(),
|
||||
new SystemTextJson(),
|
||||
new MsgPackCli(),
|
||||
new FsPickler_(),
|
||||
new Ceras_(),
|
||||
new ProtobufNetSerializer(),
|
||||
new JsonNetSerializer(),
|
||||
new BsonNetSerializer(),
|
||||
new BinaryFormatterSerializer(),
|
||||
new DataContractSerializer(),
|
||||
new HyperionSerializer(),
|
||||
new JilSerializer(),
|
||||
new SpanJsonSerializer(),
|
||||
new Utf8JsonSerializer(),
|
||||
new SystemTextJsonSerializer(),
|
||||
new MsgPackCliSerializer(),
|
||||
new FsPicklerSerializer(),
|
||||
new CerasSerializer(),
|
||||
};
|
||||
|
||||
protected static readonly ExpressionTreeFixture ExpressionTreeFixture = new ExpressionTreeFixture();
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class BinaryFormatter_ : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return (T)new BinaryFormatter().Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "BinaryFormatter";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public class BinaryFormatterSerializer : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return (T)new BinaryFormatter().Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "BinaryFormatter";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,47 +2,47 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using Benchmark.Serializers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Bson;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class BsonNet : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
private static readonly JsonSerializer Serializer = new JsonSerializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
public class BsonNetSerializer : SerializerBase
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
using (var jr = new BsonDataReader(ms))
|
||||
{
|
||||
return Serializer.Deserialize<T>(jr);
|
||||
}
|
||||
}
|
||||
private static readonly JsonSerializer Serializer = new JsonSerializer();
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
object value = input;
|
||||
if (typeof(T).IsValueType)
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
value = new[] { input };
|
||||
}
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var jw = new BsonDataWriter(ms))
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
using (var jr = new BsonDataReader(ms))
|
||||
{
|
||||
Serializer.Serialize(jw, value);
|
||||
return Serializer.Deserialize<T>(jr);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
object value = input;
|
||||
if (typeof(T).IsValueType)
|
||||
{
|
||||
value = new[] { input };
|
||||
}
|
||||
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var jw = new BsonDataWriter(ms))
|
||||
{
|
||||
Serializer.Serialize(jw, value);
|
||||
}
|
||||
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "BsonNet";
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "BsonNet";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class Ceras_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
private Ceras.CerasSerializer ceras = new Ceras.CerasSerializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
public class CerasSerializer : SerializerBase
|
||||
{
|
||||
return this.ceras.Deserialize<T>((byte[])input);
|
||||
}
|
||||
private Ceras.CerasSerializer ceras = new Ceras.CerasSerializer();
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return this.ceras.Serialize(input);
|
||||
}
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return this.ceras.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Ceras";
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return this.ceras.Serialize(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Ceras";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,33 +2,32 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class DataContract_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
public class DataContractSerializer : SerializerBase
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return (T)new DataContractSerializer(typeof(T)).ReadObject(ms);
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return (T)new System.Runtime.Serialization.DataContractSerializer(typeof(T)).ReadObject(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
new DataContractSerializer(typeof(T)).WriteObject(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new System.Runtime.Serialization.DataContractSerializer(typeof(T)).WriteObject(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "DataContract";
|
||||
public override string ToString()
|
||||
{
|
||||
return "DataContract";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,35 +2,35 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using Benchmark.Serializers;
|
||||
using MBrace.FsPickler;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class FsPickler_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
private static readonly BinarySerializer Serializer = MBrace.FsPickler.FsPickler.CreateBinarySerializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
public class FsPicklerSerializer : SerializerBase
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
private static readonly BinarySerializer Serializer = MBrace.FsPickler.FsPickler.CreateBinarySerializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
Serializer.Serialize<T>(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Serializer.Serialize<T>(ms, input);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "FsPickler";
|
||||
public override string ToString()
|
||||
{
|
||||
return "FsPickler";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,35 +2,35 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using Benchmark.Serializers;
|
||||
using Hyperion;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class Hyperion_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
private static readonly Serializer Serializer = new Hyperion.Serializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
public class HyperionSerializer : SerializerBase
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
private static readonly Serializer Serializer = new Hyperion.Serializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
Serializer.Serialize(input, ms);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Serializer.Serialize(input, ms);
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Hyperion";
|
||||
public override string ToString()
|
||||
{
|
||||
return "Hyperion";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,25 +2,25 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Text;
|
||||
using Benchmark.Serializers;
|
||||
using Jil;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class Jil_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override object Serialize<T>(T input)
|
||||
public class JilSerializer : SerializerBase
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(Jil.JSON.Serialize(input, Options.ISO8601));
|
||||
}
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(Jil.JSON.Serialize(input, Options.ISO8601));
|
||||
}
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Jil.JSON.Deserialize<T>(Encoding.UTF8.GetString((byte[])input), Options.ISO8601);
|
||||
}
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Jil.JSON.Deserialize<T>(Encoding.UTF8.GetString((byte[])input), Options.ISO8601);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Jil";
|
||||
public override string ToString()
|
||||
{
|
||||
return "Jil";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,42 +3,42 @@
|
|||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Benchmark.Serializers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class JsonNet : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
private static readonly JsonSerializer Serializer = new JsonSerializer();
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
public class JsonNetSerializer : SerializerBase
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
using (var sr = new StreamReader(ms, Encoding.UTF8))
|
||||
using (var jr = new JsonTextReader(sr))
|
||||
{
|
||||
return Serializer.Deserialize<T>(jr);
|
||||
}
|
||||
}
|
||||
private static readonly JsonSerializer Serializer = new JsonSerializer();
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
using (var sw = new StreamWriter(ms, Encoding.UTF8))
|
||||
using (var jw = new JsonTextWriter(sw))
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
using (var sr = new StreamReader(ms, Encoding.UTF8))
|
||||
using (var jr = new JsonTextReader(sr))
|
||||
{
|
||||
Serializer.Serialize(jw, input);
|
||||
return Serializer.Deserialize<T>(jr);
|
||||
}
|
||||
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "JsonNet";
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var sw = new StreamWriter(ms, Encoding.UTF8))
|
||||
using (var jw = new JsonTextWriter(sw))
|
||||
{
|
||||
Serializer.Serialize(jw, input);
|
||||
}
|
||||
|
||||
ms.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "JsonNet";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,217 +4,221 @@
|
|||
extern alias oldmsgpack;
|
||||
extern alias newmsgpack;
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class MessagePack_v1 : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
public class MessagePack_v1 : SerializerBase
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePack_v1";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePack_v2 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePack_v2";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v1_string : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v1_string";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_string : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(newmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, options: Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, options: Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_string";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePackLz4_v1 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePackLz4_v1";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePackLz4_v2 : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions LZ4BlockArray = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithCompression(newmsgpack::MessagePack.MessagePackCompression.Lz4BlockArray);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, LZ4BlockArray);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, LZ4BlockArray);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePackLz4_v2";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v1_str_lz4 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Deserialize<T>((byte[])input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Serialize<T>(input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v1_str_lz4";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_str_lz4 : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(newmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance).WithCompression(newmsgpack::MessagePack.MessagePackCompression.Lz4BlockArray);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_str_lz4";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_opt : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(OptimizedResolver.Instance);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_opt";
|
||||
}
|
||||
}
|
||||
|
||||
public class OptimizedResolver : newmsgpack::MessagePack.IFormatterResolver
|
||||
{
|
||||
public static readonly newmsgpack::MessagePack.IFormatterResolver Instance = new OptimizedResolver();
|
||||
|
||||
// configure your custom resolvers.
|
||||
private static readonly newmsgpack::MessagePack.IFormatterResolver[] Resolvers = new newmsgpack::MessagePack.IFormatterResolver[]
|
||||
{
|
||||
newmsgpack::MessagePack.Resolvers.NativeGuidResolver.Instance,
|
||||
newmsgpack::MessagePack.Resolvers.NativeDecimalResolver.Instance,
|
||||
newmsgpack::MessagePack.Resolvers.NativeDateTimeResolver.Instance,
|
||||
newmsgpack::MessagePack.Resolvers.StandardResolver.Instance,
|
||||
};
|
||||
|
||||
private OptimizedResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public newmsgpack::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return Cache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class Cache<T>
|
||||
{
|
||||
#pragma warning disable SA1401 // Fields should be private
|
||||
public static newmsgpack::MessagePack.Formatters.IMessagePackFormatter<T> Formatter;
|
||||
#pragma warning restore SA1401 // Fields should be private
|
||||
|
||||
static Cache()
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
foreach (var resolver in Resolvers)
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePack_v1";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePack_v2 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePack_v2";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v1_string : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v1_string";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_string : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options =
|
||||
newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(newmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, options: Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, options: Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_string";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePackLz4_v1 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Serialize<T>(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePackLz4_v1";
|
||||
}
|
||||
}
|
||||
|
||||
public class MessagePackLz4_v2 : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions LZ4BlockArray =
|
||||
newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithCompression(newmsgpack::MessagePack.MessagePackCompression.Lz4BlockArray);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, LZ4BlockArray);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, LZ4BlockArray);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MessagePackLz4_v2";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v1_str_lz4 : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Deserialize<T>((byte[])input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return oldmsgpack::MessagePack.LZ4MessagePackSerializer.Serialize<T>(input, oldmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v1_str_lz4";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_str_lz4 : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard
|
||||
.WithResolver(newmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance)
|
||||
.WithCompression(newmsgpack::MessagePack.MessagePackCompression.Lz4BlockArray);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_str_lz4";
|
||||
}
|
||||
}
|
||||
|
||||
public class MsgPack_v2_opt : SerializerBase
|
||||
{
|
||||
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options =
|
||||
newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(OptimizedResolver.Instance);
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Deserialize<T>((byte[])input, Options);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return newmsgpack::MessagePack.MessagePackSerializer.Serialize<T>(input, Options);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPack_v2_opt";
|
||||
}
|
||||
}
|
||||
|
||||
public class OptimizedResolver : newmsgpack::MessagePack.IFormatterResolver
|
||||
{
|
||||
public static readonly newmsgpack::MessagePack.IFormatterResolver Instance = new OptimizedResolver();
|
||||
|
||||
// configure your custom resolvers.
|
||||
private static readonly newmsgpack::MessagePack.IFormatterResolver[] Resolvers = new newmsgpack::MessagePack.IFormatterResolver[]
|
||||
{
|
||||
newmsgpack::MessagePack.Resolvers.NativeGuidResolver.Instance, newmsgpack::MessagePack.Resolvers.NativeDecimalResolver.Instance,
|
||||
newmsgpack::MessagePack.Resolvers.NativeDateTimeResolver.Instance, newmsgpack::MessagePack.Resolvers.StandardResolver.Instance,
|
||||
};
|
||||
|
||||
private OptimizedResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public newmsgpack::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return Cache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class Cache<T>
|
||||
{
|
||||
#pragma warning disable SA1401 // Fields should be private
|
||||
public static newmsgpack::MessagePack.Formatters.IMessagePackFormatter<T> Formatter;
|
||||
#pragma warning restore SA1401 // Fields should be private
|
||||
|
||||
static Cache()
|
||||
{
|
||||
var f = resolver.GetFormatter<T>();
|
||||
if (f != null)
|
||||
foreach (var resolver in Resolvers)
|
||||
{
|
||||
Formatter = f;
|
||||
return;
|
||||
var f = resolver.GetFormatter<T>();
|
||||
if (f != null)
|
||||
{
|
||||
Formatter = f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class MsgPackCli : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
public class MsgPackCliSerializer : SerializerBase
|
||||
{
|
||||
return MsgPack.Serialization.MessagePackSerializer.Get<T>().UnpackSingleObject((byte[])input);
|
||||
}
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return MsgPack.Serialization.MessagePackSerializer.Get<T>().UnpackSingleObject((byte[])input);
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return MsgPack.Serialization.MessagePackSerializer.Get<T>().PackSingleObject(input);
|
||||
}
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return MsgPack.Serialization.MessagePackSerializer.Get<T>().PackSingleObject(input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPackCli";
|
||||
public override string ToString()
|
||||
{
|
||||
return "MsgPackCli";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public class ProtobufNetSerializer : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Serializer.Serialize(ms, input);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ProtobufNet";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
using Benchmark.Serializers;
|
||||
using ProtoBuf;
|
||||
|
||||
public class
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
ProtobufNet : SerializerBase
|
||||
{
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
using (var ms = new MemoryStream((byte[])input))
|
||||
{
|
||||
return Serializer.Deserialize<T>(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
Serializer.Serialize(ms, input);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ProtobufNet";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +1,23 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class SpanJson_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override object Serialize<T>(T input)
|
||||
public class SpanJsonSerializer : SerializerBase
|
||||
{
|
||||
return SpanJson.JsonSerializer.Generic.Utf8.Serialize(input);
|
||||
}
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return SpanJson.JsonSerializer.Generic.Utf8.Serialize(input);
|
||||
}
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return SpanJson.JsonSerializer.Generic.Utf8.Deserialize<T>((byte[])input);
|
||||
}
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return SpanJson.JsonSerializer.Generic.Utf8.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "SpanJson";
|
||||
public override string ToString()
|
||||
{
|
||||
return "SpanJson";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,24 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class SystemTextJson : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override object Serialize<T>(T input)
|
||||
public class SystemTextJsonSerializer : SerializerBase
|
||||
{
|
||||
return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(input);
|
||||
}
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(input);
|
||||
}
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
var span = (byte[])input;
|
||||
return System.Text.Json.JsonSerializer.Deserialize<T>(span);
|
||||
}
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
var span = (byte[])input;
|
||||
return System.Text.Json.JsonSerializer.Deserialize<T>(span);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "SystemTextJson";
|
||||
public override string ToString()
|
||||
{
|
||||
return "SystemTextJson";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Benchmark.Serializers;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
public class Utf8Json_ : SerializerBase
|
||||
namespace Benchmark.Serializers
|
||||
{
|
||||
public override object Serialize<T>(T input)
|
||||
public class Utf8JsonSerializer : SerializerBase
|
||||
{
|
||||
return Utf8Json.JsonSerializer.Serialize(input);
|
||||
}
|
||||
public override object Serialize<T>(T input)
|
||||
{
|
||||
return Utf8Json.JsonSerializer.Serialize(input);
|
||||
}
|
||||
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Utf8Json.JsonSerializer.Deserialize<T>((byte[])input);
|
||||
public override T Deserialize<T>(object input)
|
||||
{
|
||||
return Utf8Json.JsonSerializer.Deserialize<T>((byte[])input);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче