Skip to content

Commit

Permalink
Merge pull request #1149 from JohannesDeml/benchmarkSerializerNaming
Browse files Browse the repository at this point in the history
Benchmark serializer naming
  • Loading branch information
AArnott committed Dec 20, 2020
2 parents 0bd93df + cc09f3c commit 78c29b3
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 356 deletions.
1 change: 1 addition & 0 deletions azure-pipelines.yml
Expand Up @@ -96,3 +96,4 @@ stages:
command: push
packagesToPush: $(Pipeline.Workspace)/nuget/*.nupkg
publishVstsFeed: MessagePack-CSharp/MessagePack-CI
continueOnError: true
52 changes: 26 additions & 26 deletions benchmark/SerializerBenchmark/SerializerBenchmark.cs
Expand Up @@ -31,19 +31,19 @@ public class AllSerializerBenchmark_BytesInOut
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();
Expand Down Expand Up @@ -1111,19 +1111,19 @@ public class ShortRun_AllSerializerBenchmark_BytesInOut
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();
Expand Down
29 changes: 0 additions & 29 deletions benchmark/SerializerBenchmark/Serializers/BinaryFormatter.cs

This file was deleted.

@@ -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";
}
}
}
51 changes: 28 additions & 23 deletions benchmark/SerializerBenchmark/Serializers/BsonNetSerializer.cs
Expand Up @@ -2,42 +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((byte[])input))
using (var jr = new BsonDataReader(ms))
{
return Serializer.Deserialize<T>(jr);
}
}

using (var ms = new MemoryStream())
public override object Serialize<T>(T input)
{
using (var jw = new BsonDataWriter(ms))
object value = input;
if (typeof(T).IsValueType)
{
Serializer.Serialize(jw, value);
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";
}
}
}
30 changes: 17 additions & 13 deletions benchmark/SerializerBenchmark/Serializers/CerasSerializer.cs
@@ -1,21 +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 object Serialize<T>(T input)
{
return this.ceras.Serialize(input);
}

public override string ToString()
{
return "Ceras";
}
}
}
34 changes: 19 additions & 15 deletions benchmark/SerializerBenchmark/Serializers/DataContractSerializer.cs
Expand Up @@ -2,28 +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)
{
using (var ms = new MemoryStream())
{
new System.Runtime.Serialization.DataContractSerializer(typeof(T)).WriteObject(ms, input);
ms.Flush();
return ms.ToArray();
}
}

public override string ToString()
{
new DataContractSerializer(typeof(T)).WriteObject(ms, input);
ms.Flush();
return ms.ToArray();
return "DataContract";
}
}
}
37 changes: 21 additions & 16 deletions benchmark/SerializerBenchmark/Serializers/FsPicklerSerializer.cs
Expand Up @@ -2,30 +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)
{
using (var ms = new MemoryStream())
{
Serializer.Serialize<T>(ms, input);
ms.Flush();
return ms.ToArray();
}
}

public override string ToString()
{
Serializer.Serialize<T>(ms, input);
ms.Flush();
return ms.ToArray();
return "FsPickler";
}
}
}
37 changes: 21 additions & 16 deletions benchmark/SerializerBenchmark/Serializers/HyperionSerializer.cs
Expand Up @@ -2,30 +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)
{
using (var ms = new MemoryStream())
{
Serializer.Serialize(input, ms);
ms.Flush();
return ms.ToArray();
}
}

public override string ToString()
{
Serializer.Serialize(input, ms);
ms.Flush();
return ms.ToArray();
return "Hyperion";
}
}
}

0 comments on commit 78c29b3

Please sign in to comment.