This commit is contained in:
Yoshifumi Kawai 2019-12-01 05:36:44 +09:00
Родитель 8129f02da5
Коммит e51371eb47
8 изменённых файлов: 292 добавлений и 10 удалений

Просмотреть файл

@ -100,6 +100,7 @@ namespace Benchmark
{
var instance = Activator.CreateInstance(mi.DeclaringType);
mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);
mi.DeclaringType.GetMethod("Setup").Invoke(instance, null);
var bytes = (byte[])mi.Invoke(instance, null);
return ToHumanReadableSize(bytes.Length);

Просмотреть файл

@ -1,6 +1,9 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma warning disable IDE1006
#pragma warning disable SA1516
extern alias oldmsgpack;
extern alias newmsgpack;
@ -143,4 +146,91 @@ namespace Benchmark.Models
this.upvoted.TrueEquals((bool?)obj.upvoted);
}
}
[oldmsgpack::MessagePack.MessagePackObject(true), newmsgpack::MessagePack.MessagePackObject(true)]
public class Answer2 : IGenericEquality<Answer2>
{
public int? question_id { get; set; }
public int? answer_id { get; set; }
public DateTime? locked_date { get; set; }
public DateTime? creation_date { get; set; }
public DateTime? last_edit_date { get; set; }
public DateTime? last_activity_date { get; set; }
public int? score { get; set; }
public DateTime? community_owned_date { get; set; }
public bool? is_accepted { get; set; }
public string body { get; set; }
public ShallowUser2 owner { get; set; }
public string title { get; set; }
public int? up_vote_count { get; set; }
public int? down_vote_count { get; set; }
public List<Comment2> comments { get; set; }
public string link { get; set; }
public List<string> tags { get; set; }
public bool? upvoted { get; set; }
public bool? downvoted { get; set; }
public bool? accepted { get; set; }
public ShallowUser2 last_editor { get; set; }
public int? comment_count { get; set; }
public string body_markdown { get; set; }
public string share_link { get; set; }
public bool Equals(Answer2 obj)
{
return
this.accepted.TrueEquals(obj.accepted) &&
this.answer_id.TrueEquals(obj.answer_id) &&
this.body.TrueEqualsString(obj.body) &&
this.body_markdown.TrueEqualsString(obj.body_markdown) &&
this.comment_count.TrueEquals(obj.comment_count) &&
this.comments.TrueEqualsList(obj.comments) &&
this.community_owned_date.TrueEquals(obj.community_owned_date) &&
this.creation_date.TrueEquals(obj.creation_date) &&
this.down_vote_count.TrueEquals(obj.down_vote_count) &&
this.downvoted.TrueEquals(obj.downvoted) &&
this.is_accepted.TrueEquals(obj.is_accepted) &&
this.last_activity_date.TrueEquals(obj.last_activity_date) &&
this.last_edit_date.TrueEquals(obj.last_edit_date) &&
this.last_editor.TrueEquals(obj.last_editor) &&
this.link.TrueEqualsString(obj.link) &&
this.locked_date.TrueEquals(obj.locked_date) &&
this.owner.TrueEquals(obj.owner) &&
this.question_id.TrueEquals(obj.question_id) &&
this.score.TrueEquals(obj.score) &&
this.share_link.TrueEqualsString(obj.share_link) &&
this.tags.TrueEqualsString(obj.tags) &&
this.title.TrueEqualsString(obj.title) &&
this.up_vote_count.TrueEquals(obj.up_vote_count) &&
this.upvoted.TrueEquals(obj.upvoted);
}
public bool EqualsDynamic(dynamic obj)
{
return
this.accepted.TrueEquals((bool?)obj.accepted) &&
this.answer_id.TrueEquals((int?)obj.answer_id) &&
this.body.TrueEqualsString((string)obj.body) &&
this.body_markdown.TrueEqualsString((string)obj.body_markdown) &&
this.comment_count.TrueEquals((int?)obj.comment_count) &&
this.comments.TrueEqualsListDynamic((IEnumerable<dynamic>)obj.comments) &&
this.community_owned_date.TrueEquals((DateTime?)obj.community_owned_date) &&
this.creation_date.TrueEquals((DateTime?)obj.creation_date) &&
this.down_vote_count.TrueEquals((int?)obj.down_vote_count) &&
this.downvoted.TrueEquals((bool?)obj.downvoted) &&
this.is_accepted.TrueEquals((bool?)obj.is_accepted) &&
this.last_activity_date.TrueEquals((DateTime?)obj.last_activity_date) &&
this.last_edit_date.TrueEquals((DateTime?)obj.last_edit_date) &&
((this.last_editor == null && obj.last_editor == null) || this.last_editor.EqualsDynamic(obj.last_editor)) &&
this.link.TrueEqualsString((string)obj.link) &&
this.locked_date.TrueEquals((DateTime?)obj.locked_date) &&
((this.owner == null && obj.owner == null) || this.owner.EqualsDynamic(obj.owner)) &&
this.question_id.TrueEquals((int?)obj.question_id) &&
this.score.TrueEquals((int?)obj.score) &&
this.share_link.TrueEqualsString((string)obj.share_link) &&
this.tags.TrueEqualsString((IEnumerable<string>)obj.tags) &&
this.title.TrueEqualsString((string)obj.title) &&
this.up_vote_count.TrueEquals((int?)obj.up_vote_count) &&
this.upvoted.TrueEquals((bool?)obj.upvoted);
}
}
}

Просмотреть файл

@ -1,6 +1,9 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma warning disable IDE1006
#pragma warning disable SA1516
extern alias oldmsgpack;
extern alias newmsgpack;
@ -89,4 +92,56 @@ namespace Benchmark.Models
this.upvoted.TrueEquals((bool?)obj.upvoted);
}
}
[oldmsgpack::MessagePack.MessagePackObject(true), newmsgpack::MessagePack.MessagePackObject(true)]
public class Comment2 : IGenericEquality<Comment2>
{
public int? comment_id { get; set; }
public int? post_id { get; set; }
public DateTime? creation_date { get; set; }
public PostType? post_type { get; set; }
public int? score { get; set; }
public bool? edited { get; set; }
public string body { get; set; }
public ShallowUser2 owner { get; set; }
public ShallowUser2 reply_to_user { get; set; }
public string link { get; set; }
public string body_markdown { get; set; }
public bool? upvoted { get; set; }
public bool Equals(Comment2 obj)
{
return
this.body.TrueEqualsString(obj.body) &&
this.body_markdown.TrueEqualsString(obj.body_markdown) &&
this.comment_id.TrueEquals(obj.comment_id) &&
this.creation_date.TrueEquals(obj.creation_date) &&
this.edited.TrueEquals(obj.edited) &&
this.link.TrueEqualsString(obj.link) &&
this.owner.TrueEquals(obj.owner) &&
this.post_id.TrueEquals(obj.post_id) &&
this.post_type.TrueEquals(obj.post_type) &&
this.reply_to_user.TrueEquals(obj.reply_to_user) &&
this.score.TrueEquals(obj.score) &&
this.upvoted.TrueEquals(obj.upvoted);
}
public bool EqualsDynamic(dynamic obj)
{
return
this.body.TrueEqualsString((string)obj.body) &&
this.body_markdown.TrueEqualsString((string)obj.body_markdown) &&
this.comment_id.TrueEquals((int?)obj.comment_id) &&
this.creation_date.TrueEquals((DateTime?)obj.creation_date) &&
this.edited.TrueEquals((bool?)obj.edited) &&
this.link.TrueEqualsString((string)obj.link) &&
((this.owner == null && obj.owner == null) || this.owner.EqualsDynamic(obj.owner)) &&
this.post_id.TrueEquals((int?)obj.post_id) &&
this.post_type.TrueEquals((PostType?)obj.post_type) &&
((this.reply_to_user == null && obj.reply_to_user == null) ||
this.reply_to_user.EqualsDynamic(obj.reply_to_user)) &&
this.score.TrueEquals((int?)obj.score) &&
this.upvoted.TrueEquals((bool?)obj.upvoted);
}
}
}

Просмотреть файл

@ -1,6 +1,9 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma warning disable IDE1006
#pragma warning disable SA1516
extern alias oldmsgpack;
extern alias newmsgpack;
@ -69,4 +72,43 @@ namespace Benchmark.Models
this.user_type.TrueEquals((UserType?)obj.user_type);
}
}
[oldmsgpack::MessagePack.MessagePackObject(true), newmsgpack::MessagePack.MessagePackObject(true)]
public class ShallowUser2 : IGenericEquality<ShallowUser2>
{
public int? user_id { get; set; }
public string display_name { get; set; }
public int? reputation { get; set; }
public UserType? user_type { get; set; }
public string profile_image { get; set; }
public string link { get; set; }
public int? accept_rate { get; set; }
public User.BadgeCount2 badge_counts { get; set; }
public bool Equals(ShallowUser2 obj)
{
return
this.accept_rate.TrueEquals(obj.accept_rate) &&
this.badge_counts.TrueEquals(obj.badge_counts) &&
this.display_name.TrueEqualsString(obj.display_name) &&
this.link.TrueEqualsString(obj.link) &&
this.profile_image.TrueEqualsString(obj.profile_image) &&
this.reputation.TrueEquals(obj.reputation) &&
this.user_id.TrueEquals(obj.user_id) &&
this.user_type.TrueEquals(obj.user_type);
}
public bool EqualsDynamic(dynamic obj)
{
return
this.accept_rate.TrueEquals((int?)obj.accept_rate) &&
((this.badge_counts == null && obj.badge_counts == null) || this.badge_counts.EqualsDynamic(obj.badge_counts)) &&
this.display_name.TrueEqualsString((string)obj.display_name) &&
this.link.TrueEqualsString((string)obj.link) &&
this.profile_image.TrueEqualsString((string)obj.profile_image) &&
this.reputation.TrueEquals((int?)obj.reputation) &&
this.user_id.TrueEquals((int?)obj.user_id) &&
this.user_type.TrueEquals((UserType?)obj.user_type);
}
}
}

Просмотреть файл

@ -1,6 +1,9 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma warning disable IDE1006
#pragma warning disable SA1516
extern alias oldmsgpack;
extern alias newmsgpack;
@ -190,5 +193,29 @@ namespace Benchmark.Models
this.gold.TrueEquals((int?)obj.gold);
}
}
[oldmsgpack::MessagePack.MessagePackObject(true), newmsgpack::MessagePack.MessagePackObject(true)]
public class BadgeCount2 : IGenericEquality<BadgeCount2>
{
public int? gold { get; set; }
public int? silver { get; set; }
public int? bronze { get; set; }
public bool Equals(BadgeCount2 obj)
{
return
this.bronze.TrueEquals(obj.bronze) &&
this.silver.TrueEquals(obj.silver) &&
this.gold.TrueEquals(obj.gold);
}
public bool EqualsDynamic(dynamic obj)
{
return
this.bronze.TrueEquals((int?)obj.bronze) &&
this.silver.TrueEquals((int?)obj.silver) &&
this.gold.TrueEquals((int?)obj.gold);
}
}
}
}

Просмотреть файл

@ -11,8 +11,12 @@ namespace ConsoleApp1
{
private static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
////BenchmarkRunner.Run<ShortRun_AllSerializerBenchmark_BytesInOut>();
#if !DEBUG
//BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
BenchmarkRunner.Run<ShortRun_AllSerializerBenchmark_BytesInOut>();
#else
BenchmarkRunner.Run<ShortRun_AllSerializerBenchmark_BytesInOut>(new BenchmarkDotNet.Configs.DebugInProcessConfig());
#endif
}
}
}

Просмотреть файл

@ -1096,16 +1096,20 @@ namespace Benchmark
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;
private bool isContractless;
// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
new MessagePack_v2(),
new MsgPack_v2_opt(),
new MessagePackLz4_v1(),
new MessagePackLz4_v2(),
new MsgPack_v2_opt(),
// new MsgPack_v2_string(),
// new MsgPack_v2_str_lz4(),
new MsgPack_v1_string(),
new MsgPack_v2_string(),
new MsgPack_v1_str_lz4(),
new MsgPack_v2_str_lz4(),
new ProtobufNet(),
new JsonNet(),
new BinaryFormatter_(),
@ -1127,6 +1131,8 @@ namespace Benchmark
// models
protected static readonly Benchmark.Models.Answer AnswerInput = ExpressionTreeFixture.Create<Benchmark.Models.Answer>();
// not same data so does not gurantee correctly.
protected static readonly Benchmark.Models.Answer2 Answer2Input = ExpressionTreeFixture.Create<Benchmark.Models.Answer2>();
private object IntOutput;
private object AnswerOutput;
@ -1134,22 +1140,53 @@ namespace Benchmark
[GlobalSetup]
public void Setup()
{
this.isContractless = (Serializer is MsgPack_v1_string) || (Serializer is MsgPack_v2_string) || (Serializer is MsgPack_v1_str_lz4) || (Serializer is MsgPack_v2_str_lz4);
// primitives
this.IntOutput = this.Serializer.Serialize(IntInput);
// models
this.AnswerOutput = this.Serializer.Serialize(AnswerInput);
if (isContractless)
{
this.AnswerOutput = this.Serializer.Serialize(Answer2Input);
}
else
{
this.AnswerOutput = this.Serializer.Serialize(AnswerInput);
}
}
// Serialize
[Benchmark] public object _PrimitiveIntSerialize() => this.Serializer.Serialize(IntInput);
/* [Benchmark] public object _PrimitiveIntSerialize() => this.Serializer.Serialize(IntInput); */
[Benchmark] public object AnswerSerialize() => this.Serializer.Serialize(AnswerInput);
[Benchmark]
public object AnswerSerialize()
{
if (isContractless)
{
return this.Serializer.Serialize(Answer2Input);
}
else
{
return this.Serializer.Serialize(AnswerInput);
}
}
// Deserialize
[Benchmark] public Int32 _PrimitiveIntDeserialize() => this.Serializer.Deserialize<Int32>(this.IntOutput);
/* [Benchmark] public Int32 _PrimitiveIntDeserialize() => this.Serializer.Deserialize<Int32>(this.IntOutput); */
[Benchmark] public Answer AnswerDeserialize() => this.Serializer.Deserialize<Answer>(this.AnswerOutput);
[Benchmark]
public object AnswerDeserialize()
{
if (isContractless)
{
return this.Serializer.Deserialize<Answer2>(this.AnswerOutput);
}
else
{
return this.Serializer.Deserialize<Answer>(this.AnswerOutput);
}
}
}
[Config(typeof(BenchmarkConfig))]

Просмотреть файл

@ -34,6 +34,19 @@ public class MessagePack_v2 : SerializerBase
}
}
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 class MsgPack_v2_string : SerializerBase
{
private static readonly newmsgpack::MessagePack.MessagePackSerializerOptions Options = newmsgpack::MessagePack.MessagePackSerializerOptions.Standard.WithResolver(newmsgpack::MessagePack.Resolvers.ContractlessStandardResolver.Instance);
@ -77,6 +90,19 @@ public class MessagePackLz4_v2 : SerializerBase
}
}
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 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);