Skip to content

Commit

Permalink
moved benchmarks to test full serialize+deserialize cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Jun 28, 2017
1 parent e2f9aec commit b2f40f6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 58 deletions.
1 change: 1 addition & 0 deletions Hyperion.Benchmarks/Hyperion.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets" Condition="Exists('..\packages\Microsoft.Diagnostics.Tracing.TraceEvent.1.0.41\build\Microsoft.Diagnostics.Tracing.TraceEvent.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
4 changes: 4 additions & 0 deletions Hyperion.Benchmarks/Prolog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ public void Setup()
public void Cleanup()
{
Stream.Dispose();
Clean();
}

protected virtual void Init()
{
Serializer = new Serializer();
}

protected virtual void Clean() { }

#endregion

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -66,6 +69,7 @@ protected void Serialize<T>(T elem)
protected void Deserialize<T>()
{
Serializer.Deserialize<T>(Stream);
Stream.Position = 0;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
8 changes: 4 additions & 4 deletions Hyperion.Benchmarks/SerializeClassesBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ protected override void Init()

#endregion

[Benchmark] public void Serialize_CyclicReferences() => Serialize(cyclic);
[Benchmark] public void Serialize_VirtualClasses() => Serialize(virtualObject);
[Benchmark] public void Serialize_LargeSealedClasses() => Serialize(sealedObject);
[Benchmark] public void Serialize_GenericClasses() => Serialize(genericObject);
[Benchmark] public void Cyclic_References() => SerializeAndDeserialize(cyclic);
[Benchmark] public void Virtual_Classes() => SerializeAndDeserialize(virtualObject);
[Benchmark] public void Large_Sealed_Classes() => SerializeAndDeserialize(sealedObject);
[Benchmark] public void Generic_Classes() => SerializeAndDeserialize(genericObject);
}

#region test data types
Expand Down
14 changes: 7 additions & 7 deletions Hyperion.Benchmarks/SerializeCollectionsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ namespace Hyperion.Benchmarks
{
public class SerializeCollectionsBenchmark : HyperionBenchmark
{
[Benchmark] public void Serialize_ByteArray() => Serialize(new byte[] { 123, 134, 11, 122, 1 });
[Benchmark] public void Serialize_StringArray() => Serialize(new[] { "abc", "cbd0", "sdsd4", "4dfg", "sfsdf44g" });
[Benchmark] public void Serialize_Dictionary() => Serialize(new Dictionary<string, string>
[Benchmark] public void Byte_Array() => SerializeAndDeserialize(new byte[] { 123, 134, 11, 122, 1 });
[Benchmark] public void String_Array() => SerializeAndDeserialize(new[] { "abc", "cbd0", "sdsd4", "4dfg", "sfsdf44g" });
[Benchmark] public void Dictionary() => SerializeAndDeserialize(new Dictionary<string, string>
{
["abc"] = "aaa",
["dsdf"] = "asdab",
["fms0"] = "sdftu"
});
[Benchmark] public void Serialize_ArrayList() => Serialize(new List<string> { "asdad", "asdabs3", "sfsdf44g", "asdf4r", "sfsdf44g" });
[Benchmark] public void Serialize_LinkedList() => Serialize(new LinkedList<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
[Benchmark] public void Serialize_HashSet() => Serialize(new HashSet<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
[Benchmark] public void Serialize_SortedSet() => Serialize(new SortedSet<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
[Benchmark] public void Array_List() => SerializeAndDeserialize(new List<string> { "asdad", "asdabs3", "sfsdf44g", "asdf4r", "sfsdf44g" });
[Benchmark] public void Linked_List() => SerializeAndDeserialize(new LinkedList<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
[Benchmark] public void Hash_Set() => SerializeAndDeserialize(new HashSet<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
[Benchmark] public void Sorted_Set() => SerializeAndDeserialize(new SortedSet<string>(new[] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }));
}
}
12 changes: 6 additions & 6 deletions Hyperion.Benchmarks/SerializeFSharpDataTypesBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ protected override void Init()

#endregion

[Benchmark] public void Serialize_DiscriminatedUnion() => Serialize(du);
[Benchmark] public void Serialize_Struct_DiscriminatedUnion() => Serialize(sdu);
[Benchmark] public void Serialize_Record() => Serialize(record);
[Benchmark] public void Serialize_RecordWithMap() => Serialize(TestMap.createRecordWithMap);
[Benchmark] public void Serialize_FSharpList() => Serialize(list);
[Benchmark] public void Serialize_FSharpSet() => Serialize(set);
[Benchmark] public void Discriminated_Union() => SerializeAndDeserialize(du);
[Benchmark] public void Struct_Discriminated_Union() => SerializeAndDeserialize(sdu);
[Benchmark] public void Record() => SerializeAndDeserialize(record);
[Benchmark] public void Record_With_Map() => SerializeAndDeserialize(TestMap.createRecordWithMap);
[Benchmark] public void FSharp_List() => SerializeAndDeserialize(list);
[Benchmark] public void FSharp_Set() => SerializeAndDeserialize(set);
}
}
10 changes: 5 additions & 5 deletions Hyperion.Benchmarks/SerializeImmutableCollectionsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace Hyperion.Benchmarks
{
public class SerializeImmutableCollectionsBenchmark : HyperionBenchmark
{
[Benchmark] public void Serialize_ImmutableArray() => Serialize(ImmutableArray.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Serialize_ImmutableList() => Serialize(ImmutableList.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Serialize_ImmutableHashSet() => Serialize(ImmutableHashSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Serialize_ImmutableSortedSet() => Serialize(ImmutableSortedSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Serialize_ImmutableDictionary() => Serialize(ImmutableDictionary.CreateRange(new[]
[Benchmark] public void Immutable_Array() => SerializeAndDeserialize(ImmutableArray.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Immutable_List() => SerializeAndDeserialize(ImmutableList.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Immutable_Hash_Set() => SerializeAndDeserialize(ImmutableHashSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Immutable_Sorted_Set() => SerializeAndDeserialize(ImmutableSortedSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg", "adafd0xd" }));
[Benchmark] public void Immutable_Dictionary() => SerializeAndDeserialize(ImmutableDictionary.CreateRange(new[]
{
new KeyValuePair<string, string>("key1", "value1"),
new KeyValuePair<string, string>("key2", "value2"),
Expand Down
66 changes: 33 additions & 33 deletions Hyperion.Benchmarks/SerializePrimitivesBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,40 @@ protected override void Init()

#endregion

[Benchmark] public void Serialize_Boolean() => Serialize(true);
[Benchmark] public void Serialize_Byte() => Serialize((byte)123);
[Benchmark] public void Serialize_SByte() => Serialize((sbyte)123);
[Benchmark] public void Serialize_Int16() => Serialize((short)1234);
[Benchmark] public void Serialize_UInt16() => Serialize((ushort)1234);
[Benchmark] public void Serialize_Int32() => Serialize(12345);
[Benchmark] public void Serialize_UInt32() => Serialize(12345U);
[Benchmark] public void Serialize_Int64() => Serialize(123456L);
[Benchmark] public void Serialize_UInt64() => Serialize(123456UL);
[Benchmark] public void Serialize_Single() => Serialize(123456.34F);
[Benchmark] public void Serialize_Double() => Serialize(123456.34D);
[Benchmark] public void Serialize_Decimal() => Serialize(123456.34M);
[Benchmark] public void Serialize_Guid() => Serialize(guid);
[Benchmark] public void Serialize_DateTime() => Serialize(dateTime);
[Benchmark] public void Serialize_TimeSpan() => Serialize(time);
[Benchmark] public void Serialize_String() => Serialize(str);
[Benchmark] public void Serialize_Type() => Serialize(typeof(int));
[Benchmark] public void Boolean() => SerializeAndDeserialize(true);
[Benchmark] public void Byte() => SerializeAndDeserialize((byte)123);
[Benchmark] public void SByte() => SerializeAndDeserialize((sbyte)123);
[Benchmark] public void Int16() => SerializeAndDeserialize((short)1234);
[Benchmark] public void UInt16() => SerializeAndDeserialize((ushort)1234);
[Benchmark] public void Int32() => SerializeAndDeserialize(12345);
[Benchmark] public void UInt32() => SerializeAndDeserialize(12345U);
[Benchmark] public void Int64() => SerializeAndDeserialize(123456L);
[Benchmark] public void UInt64() => SerializeAndDeserialize(123456UL);
[Benchmark] public void Single() => SerializeAndDeserialize(123456.34F);
[Benchmark] public void Double() => SerializeAndDeserialize(123456.34D);
[Benchmark] public void Decimal() => SerializeAndDeserialize(123456.34M);
[Benchmark] public void Guids() => SerializeAndDeserialize(guid);
[Benchmark] public void DateTimes() => SerializeAndDeserialize(dateTime);
[Benchmark] public void TimeSpan() => SerializeAndDeserialize(time);
[Benchmark] public void String() => SerializeAndDeserialize(str);
[Benchmark] public void Type() => SerializeAndDeserialize(typeof(int));

[Benchmark] public void Serialize_Tuple1() => Serialize(Tuple.Create(1234));
[Benchmark] public void Serialize_Tuple2() => Serialize(Tuple.Create(1234, "hello world"));
[Benchmark] public void Serialize_Tuple3() => Serialize(Tuple.Create(1234, "hello world", true));
[Benchmark] public void Serialize_Tuple4() => Serialize(Tuple.Create(1234, "hello world", true, typeof(int)));
[Benchmark] public void Serialize_Tuple5() => Serialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL));
[Benchmark] public void Serialize_Tuple6() => Serialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime));
[Benchmark] public void Serialize_Tuple7() => Serialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time));
[Benchmark] public void Serialize_Tuple8() => Serialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time, guid));
[Benchmark] public void Tuple1() => SerializeAndDeserialize(Tuple.Create(1234));
[Benchmark] public void Tuple2() => SerializeAndDeserialize(Tuple.Create(1234, "hello world"));
[Benchmark] public void Tuple3() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true));
[Benchmark] public void Tuple4() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true, typeof(int)));
[Benchmark] public void Tuple5() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL));
[Benchmark] public void Tuple6() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime));
[Benchmark] public void Tuple7() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time));
[Benchmark] public void Tuple8() => SerializeAndDeserialize(Tuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time, guid));

[Benchmark] public void Serialize_ValueTuple1() => Serialize(ValueTuple.Create(1234));
[Benchmark] public void Serialize_ValueTuple2() => Serialize(ValueTuple.Create(1234, "hello world"));
[Benchmark] public void Serialize_ValueTuple3() => Serialize(ValueTuple.Create(1234, "hello world", true));
[Benchmark] public void Serialize_ValueTuple4() => Serialize(ValueTuple.Create(1234, "hello world", true, typeof(int)));
[Benchmark] public void Serialize_ValueTuple5() => Serialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL));
[Benchmark] public void Serialize_ValueTuple6() => Serialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime));
[Benchmark] public void Serialize_ValueTuple7() => Serialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time));
[Benchmark] public void Serialize_ValueTuple8() => Serialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time, guid));
[Benchmark] public void ValueTuple1() => SerializeAndDeserialize(ValueTuple.Create(1234));
[Benchmark] public void ValueTuple2() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world"));
[Benchmark] public void ValueTuple3() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true));
[Benchmark] public void ValueTuple4() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true, typeof(int)));
[Benchmark] public void ValueTuple5() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL));
[Benchmark] public void ValueTuple6() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime));
[Benchmark] public void ValueTuple7() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time));
[Benchmark] public void ValueTuple8() => SerializeAndDeserialize(ValueTuple.Create(1234, "hello world", true, typeof(int), 345666UL, dateTime, time, guid));
}
}
6 changes: 3 additions & 3 deletions Hyperion.Benchmarks/SerializeStructsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ protected override void Init()

#endregion

[Benchmark] public void Serialize_Enums() => Serialize(testEnum);
[Benchmark] public void Serialize_StandardValueTypes() => Serialize(standardValue);
[Benchmark] public void Serialize_BlittableValueTypes() => Serialize(blittableValue);
[Benchmark] public void Enums() => SerializeAndDeserialize(testEnum);
[Benchmark] public void Standard_Value_Types() => SerializeAndDeserialize(standardValue);
[Benchmark] public void Blittable_Value_Types() => SerializeAndDeserialize(blittableValue);
}

#region test data types
Expand Down

0 comments on commit b2f40f6

Please sign in to comment.