forked from akkadotnet/Hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prolog.cs
82 lines (70 loc) · 2.15 KB
/
Prolog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#region copyright
// -----------------------------------------------------------------------
// <copyright file="Prolog.cs" company="Akka.NET Team">
// Copyright (C) 2015-2016 AsynkronIT <https://github.com/AsynkronIT>
// Copyright (C) 2016-2016 Akka.NET Team <https://github.com/akkadotnet>
// </copyright>
// -----------------------------------------------------------------------
#endregion
using System.IO;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
namespace Hyperion.Benchmarks
{
public class HyperionConfig : ManualConfig
{
public HyperionConfig()
{
Add(StatisticColumn.Mean, StatisticColumn.Min, StatisticColumn.Max, StatisticColumn.OperationsPerSecond);
Add(MarkdownExporter.GitHub);
Add(MemoryDiagnoser.Default);
}
}
[Config(typeof(HyperionConfig))]
public abstract class HyperionBenchmark
{
#region init
protected Serializer Serializer;
protected MemoryStream Stream;
[GlobalSetup]
public void Setup()
{
Stream = new MemoryStream();
Init();
}
[GlobalCleanup]
public void Cleanup()
{
Stream.Dispose();
Clean();
}
protected virtual void Init()
{
Serializer = new Serializer();
}
protected virtual void Clean() { }
#endregion
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void Serialize<T>(T elem)
{
Serializer.Serialize(elem, Stream);
Stream.Position = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void Deserialize<T>()
{
Serializer.Deserialize<T>(Stream);
Stream.Position = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void SerializeAndDeserialize<T>(T elem)
{
Serialize(elem);
Deserialize<T>();
}
}
}