forked from Cysharp/MemoryPack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
128 lines (87 loc) · 3.48 KB
/
Program.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Benchmark.Benchmarks;
using Benchmark.Micro;
using Benchmark.Models;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BinaryPack.Models;
using BinaryPack.Models.Helpers;
using BinaryPack.Models.Interfaces;
using Iced.Intel;
using MemoryPack;
using MemoryPack.Compression;
using MemoryPack.Formatters;
using System.Reflection;
#if !DEBUG
var config = ManualConfig.CreateMinimumViable()
.AddDiagnoser(MemoryDiagnoser.Default)
// .AddColumn(StatisticColumn.OperationsPerSecond)
.AddExporter(DefaultExporters.Plain)
.AddExporter(MarkdownExporter.Default)
.AddJob(Job.Default.WithWarmupCount(1).WithIterationCount(1)); // .AddJob(Job.ShortRun);
//BenchmarkSwitcher.FromAssembly(Assembly.GetEntryAssembly()!).Run(args, config);
//BenchmarkRunner.Run<Utf8Decoding>(config, args);
//BenchmarkSwitcher.FromAssembly(Assembly.GetEntryAssembly()!).RunAllJoined(config);
// BenchmarkRunner.Run(Assembly.GetEntryAssembly()!, config, args);
//BenchmarkRunner.Run<SerializeInt>(config, args);
//BenchmarkRunner.Run<SerializeTest<MyClass>>(config, args);
//BenchmarkRunner.Run<RawSerialize>(config, args);
// BenchmarkRunner.Run<ConcurrentQueueVsStack>(config, args);
BenchmarkRunner.Run<ListFormatterVsDirect>(config, args);
//BenchmarkRunner.Run<Utf16VsUtf8>(config, args);
//BenchmarkRunner.Run<SerializeTest<NeuralNetworkLayerModel>>(config, args);
// BenchmarkRunner.Run<DeserializeTest<NeuralNetworkLayerModel>>(config, args);
//BenchmarkRunner.Run<StaticDictionaryFormatterCheck>(config, args);
//BenchmarkRunner.Run<SerializeTest<JsonResponseModel>>(config, args);
//BenchmarkRunner.Run<DeserializeTest<JsonResponseModel>>(config, args);
//BenchmarkRunner.Run<SerializeTest<Vector3[]>>(config, args);
//BenchmarkRunner.Run<DeserializeTest<Vector3[]>>(config, args);
//BenchmarkRunner.Run<StaticAbstractVsFormatter>(config, args);
//BenchmarkRunner.Run<Compression<JsonResponseModel>>(config, args);
//BenchmarkRunner.Run<Compression<Vector3[]>>(config, args);
//BenchmarkRunner.Run<Compression<NeuralNetworkLayerModel>>(config, args);
//BenchmarkRunner.Run<GetLocalVsStaticField>(config, args);
//BenchmarkRunner.Run<VersionTolerant>(config, args);
//BenchmarkSwitcher.FromTypes(new[]{
// typeof(SerializeTest<>),
// typeof(DeserializeTest<>) })
// .RunAllJoined(config);
#endif
#if DEBUG
var c = new StaticDictionaryFormatterCheck();
c.DeserializeCurrent();
c.DeserializeImprovement();
c.DeserializeCurrent();
c.DeserializeImprovement();
var model = new JsonResponseModel(true);
var model2 = Enumerable.Repeat(new Vector3 { X = 10.3f, Y = 40.5f, Z = 13411.3f }, 1000).ToArray();
using var compressor = new BrotliCompressor();
MemoryPackSerializer.Serialize(compressor, model2);
var foo = compressor.ToArray();
using var decompressor = new BrotliDecompressor();
var foo2 = decompressor.Decompress(foo);
Check<JsonResponseModel>();
Check<NeuralNetworkLayerModel>();
void Check<T>()
where T : IInitializable, IEquatable<T>, new()
{
var model = new T();
model.Initialize();
var bin = MemoryPackSerializer.Serialize(model);
var model2 = MemoryPackSerializer.Deserialize<T>(bin);
var ok = model.Equals(model2);
Console.WriteLine(typeof(T) + " is " + (ok ? "ok" : "ng"));
}
[MemoryPackable]
public partial class Test
{
public float[] F = default!;
public Test()
{
// _ = new TestFormatter();
}
}
#endif