Skip to content

Commit 2c3df33

Browse files
Added benchmarks (#16)
1 parent 2af09b8 commit 2c3df33

File tree

5 files changed

+259
-1
lines changed

5 files changed

+259
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
<ServerGarbageCollection>true</ServerGarbageCollection>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Akka.Serialization.Hyperion" Version="1.3.0-beta50" />
11+
<PackageReference Include="BenchmarkDotNet" Version="0.10.9" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Akka.Serialization.MessagePack\Akka.Serialization.MessagePack.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Environments;
4+
using BenchmarkDotNet.Jobs;
5+
using BenchmarkDotNet.Running;
6+
using BenchmarkDotNet.Toolchains.CsProj;
7+
8+
namespace Akka.Serialization.MessagePack.Benchmarks
9+
{
10+
public class MyConfig : ManualConfig
11+
{
12+
public MyConfig()
13+
{
14+
Add(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp20).With(Platform.X64).WithGcServer(true).WithId("NETCORE 2.0"));
15+
}
16+
}
17+
18+
class Program
19+
{
20+
static void Main(string[] args)
21+
{
22+
BenchmarkRunner.Run<SerializationBenchmarks>();
23+
24+
Console.ReadLine();
25+
}
26+
}
27+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Akka.Actor;
5+
using Akka.Configuration;
6+
using Akka.Util.Internal;
7+
using BenchmarkDotNet.Attributes;
8+
using MessagePack;
9+
10+
namespace Akka.Serialization.MessagePack.Benchmarks
11+
{
12+
[Config(typeof(MyConfig))]
13+
[MemoryDiagnoser]
14+
public class SerializationBenchmarks
15+
{
16+
private MsgPackSerializer MsgPackSerializer;
17+
private HyperionSerializer HyperionSerializer;
18+
private NewtonSoftJsonSerializer NewtonSoftJsonSerializer;
19+
20+
private const string TestString = "simple long string";
21+
22+
private SimpleObject TestSimpleObject = new SimpleObject()
23+
{
24+
MyProperty1 = 1, MyProperty2 = 2, MyProperty3 = 3, MyProperty4 = 4, MyProperty5 = 5
25+
};
26+
27+
private SimpleOptimizedObject TestSimpleObjectOptimized = new SimpleOptimizedObject
28+
{
29+
MyProperty1 = 1, MyProperty2 = 2, MyProperty3 = 3, MyProperty4 = 4, MyProperty5 = 5
30+
};
31+
32+
private TypelessObject TestTypelessObject = new TypelessObject
33+
{
34+
MyProperty1 = Int16.MaxValue, MyProperty2 = Single.MaxValue, MyProperty3 = TestString, MyProperty4 = TimeSpan.FromDays(3), MyProperty5 = new Uri("http://somesite.com")
35+
};
36+
37+
public SerializationBenchmarks()
38+
39+
{
40+
var config = ConfigurationFactory.ParseString("akka.suppress-json-serializer-warning=true");
41+
var system = ActorSystem.Create("SerializationBenchmarks", config);
42+
43+
MsgPackSerializer = new MsgPackSerializer(system.AsInstanceOf<ExtendedActorSystem>());
44+
HyperionSerializer = new HyperionSerializer(
45+
system.AsInstanceOf<ExtendedActorSystem>(),
46+
new HyperionSerializerSettings(false, false, typeof(SimpleTypesProvider)));
47+
NewtonSoftJsonSerializer = new NewtonSoftJsonSerializer(system.AsInstanceOf<ExtendedActorSystem>());
48+
}
49+
50+
[Benchmark]
51+
public string MsgPack_serialize_string()
52+
{
53+
var bytes = MsgPackSerializer.ToBinary(TestString);
54+
return MsgPackSerializer.FromBinary<string>(bytes);
55+
}
56+
57+
[Benchmark]
58+
public string Hyperion_serialize_string()
59+
{
60+
var bytes = HyperionSerializer.ToBinary(TestString);
61+
return HyperionSerializer.FromBinary<string>(bytes);
62+
}
63+
64+
[Benchmark]
65+
public string JsonNet_serialize_string()
66+
{
67+
var bytes = NewtonSoftJsonSerializer.ToBinary(TestString);
68+
return NewtonSoftJsonSerializer.FromBinary<string>(bytes);
69+
}
70+
71+
[Benchmark]
72+
public SimpleObject MsgPack_serialize_SimpleObject()
73+
{
74+
var bytes = MsgPackSerializer.ToBinary(TestSimpleObject);
75+
return MsgPackSerializer.FromBinary<SimpleObject>(bytes);
76+
}
77+
78+
[Benchmark]
79+
public SimpleObject Hyperion_serialize_SimpleObject()
80+
{
81+
var bytes = HyperionSerializer.ToBinary(TestSimpleObject);
82+
return HyperionSerializer.FromBinary<SimpleObject>(bytes);
83+
}
84+
85+
[Benchmark]
86+
public SimpleObject JsonNet_serialize_SimpleObject()
87+
{
88+
var bytes = NewtonSoftJsonSerializer.ToBinary(TestSimpleObject);
89+
return NewtonSoftJsonSerializer.FromBinary<SimpleObject>(bytes);
90+
}
91+
92+
[Benchmark]
93+
public SimpleOptimizedObject MsgPack_serialize_SimpleOptimizedObject_int_keys()
94+
{
95+
var bytes = MsgPackSerializer.ToBinary(TestSimpleObjectOptimized);
96+
return MsgPackSerializer.FromBinary<SimpleOptimizedObject>(bytes);
97+
}
98+
99+
[Benchmark]
100+
public SimpleOptimizedObject Hyperion_serialize_SimpleOptimizedObject_preregistered()
101+
{
102+
var bytes = HyperionSerializer.ToBinary(TestSimpleObjectOptimized);
103+
return HyperionSerializer.FromBinary<SimpleOptimizedObject>(bytes);
104+
}
105+
106+
[Benchmark]
107+
public TypelessObject MsgPack_serialize_TypelessObject()
108+
{
109+
var bytes = MsgPackSerializer.ToBinary(TestTypelessObject);
110+
return MsgPackSerializer.FromBinary<TypelessObject>(bytes);
111+
}
112+
113+
[Benchmark]
114+
public TypelessObject Hyperion_serialize_TypelessObject()
115+
{
116+
var bytes = HyperionSerializer.ToBinary(TestTypelessObject);
117+
return HyperionSerializer.FromBinary<TypelessObject>(bytes);
118+
}
119+
120+
[Benchmark]
121+
public TypelessObject JsonNet_serialize_TypelessObject()
122+
{
123+
var bytes = NewtonSoftJsonSerializer.ToBinary(TestTypelessObject);
124+
return NewtonSoftJsonSerializer.FromBinary<TypelessObject>(bytes);
125+
}
126+
}
127+
128+
public class SimpleObject
129+
{
130+
public int MyProperty1 { get; set; }
131+
public int MyProperty2 { get; set; }
132+
public int MyProperty3 { get; set; }
133+
public int MyProperty4 { get; set; }
134+
public int MyProperty5 { get; set; }
135+
}
136+
137+
[MessagePackObject]
138+
public class SimpleOptimizedObject
139+
{
140+
[Key(0)]
141+
public int MyProperty1 { get; set; }
142+
143+
[Key(1)]
144+
public int MyProperty2 { get; set; }
145+
146+
[Key(2)]
147+
public int MyProperty3 { get; set; }
148+
149+
[Key(3)]
150+
public int MyProperty4 { get; set; }
151+
152+
[Key(4)]
153+
public int MyProperty5 { get; set; }
154+
}
155+
156+
public class TypelessObject
157+
{
158+
public object MyProperty1 { get; set; }
159+
public object MyProperty2 { get; set; }
160+
public object MyProperty3 { get; set; }
161+
public object MyProperty4 { get; set; }
162+
public object MyProperty5 { get; set; }
163+
}
164+
165+
public class SimpleTypesProvider : IKnownTypesProvider
166+
{
167+
public SimpleTypesProvider(ExtendedActorSystem system)
168+
{
169+
if (system == null)
170+
throw new ArgumentNullException(nameof(system));
171+
}
172+
173+
public IEnumerable<Type> GetKnownTypes() => new Type[] { typeof(SimpleOptimizedObject) };
174+
}
175+
}

Akka.Serialization.MessagePack.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.14
4+
VisualStudioVersion = 15.0.26730.10
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Serialization.MessagePack", "Akka.Serialization.MessagePack\Akka.Serialization.MessagePack.csproj", "{0EA6EE13-61B2-4CBD-9241-C19ECA04C015}"
77
EndProject
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
README.md = README.md
1515
EndProjectSection
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Serialization.MessagePack.Benchmarks", "Akka.Serialization.MessagePack.Benchmarks\Akka.Serialization.MessagePack.Benchmarks.csproj", "{A132C115-CCD5-45F0-9D6C-EBFEFF8CB208}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -32,8 +34,15 @@ Global
3234
{F1DBA496-B62F-436B-879A-481595B74102}.Debug|Any CPU.Build.0 = Debug|Any CPU
3335
{F1DBA496-B62F-436B-879A-481595B74102}.Release|Any CPU.ActiveCfg = Release|Any CPU
3436
{F1DBA496-B62F-436B-879A-481595B74102}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{A132C115-CCD5-45F0-9D6C-EBFEFF8CB208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{A132C115-CCD5-45F0-9D6C-EBFEFF8CB208}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{A132C115-CCD5-45F0-9D6C-EBFEFF8CB208}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{A132C115-CCD5-45F0-9D6C-EBFEFF8CB208}.Release|Any CPU.Build.0 = Release|Any CPU
3541
EndGlobalSection
3642
GlobalSection(SolutionProperties) = preSolution
3743
HideSolutionNode = FALSE
3844
EndGlobalSection
45+
GlobalSection(ExtensibilityGlobals) = postSolution
46+
SolutionGuid = {9946F5AB-875A-4642-8890-2D25325D163B}
47+
EndGlobalSection
3948
EndGlobal

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,34 @@ akka {
4141
}
4242
```
4343

44+
## Benchmarks
45+
``` ini
46+
47+
BenchmarkDotNet=v0.10.9, OS=Windows 10 Redstone 2 (10.0.15063)
48+
Processor=Intel Core i5-6400 CPU 2.70GHz (Skylake), ProcessorCount=4
49+
Frequency=2648439 Hz, Resolution=377.5809 ns, Timer=TSC
50+
.NET Core SDK=2.0.0
51+
[Host] : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT
52+
NETCORE 2.0 : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT
53+
54+
Job=NETCORE 2.0 Platform=X64 Runtime=Core
55+
Server=True Toolchain=CoreCsProj
56+
57+
```
58+
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
59+
|------------------------------------------------------- |------------:|-----------:|-----------:|-------:|----------:|
60+
| MsgPack_serialize_string | 248.7 ns | 2.221 ns | 2.078 ns | 0.0029 | 112 B |
61+
| Hyperion_serialize_string | 414.2 ns | 5.646 ns | 5.281 ns | 0.0257 | 832 B |
62+
| JsonNet_serialize_string | 1,854.9 ns | 36.749 ns | 43.748 ns | 0.1355 | 4336 B |
63+
| MsgPack_serialize_SimpleObject | 351.6 ns | 5.425 ns | 5.074 ns | 0.0037 | 136 B |
64+
| Hyperion_serialize_SimpleObject | 965.3 ns | 12.820 ns | 11.992 ns | 0.0331 | 1112 B |
65+
| JsonNet_serialize_SimpleObject | 23,832.4 ns | 339.575 ns | 317.639 ns | 0.4008 | 14576 B |
66+
| MsgPack_serialize_SimpleOptimizedObject_int_keys | 200.1 ns | 1.425 ns | 1.333 ns | 0.0019 | 72 B |
67+
| Hyperion_serialize_SimpleOptimizedObject_preregistered | 493.4 ns | 6.110 ns | 5.715 ns | 0.0216 | 712 B |
68+
| MsgPack_serialize_TypelessObject | 2,096.3 ns | 21.150 ns | 19.784 ns | 0.0120 | 568 B |
69+
| Hyperion_serialize_TypelessObject | 5,698.9 ns | 34.648 ns | 32.410 ns | 0.1465 | 4952 B |
70+
| JsonNet_serialize_TypelessObject | 42,583.6 ns | 291.306 ns | 258.235 ns | 0.3342 | 13960 B |
71+
72+
4473
## Maintainer
4574
- [alexvaluyskiy](https://github.com/alexvaluyskiy)

0 commit comments

Comments
 (0)