Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

History

History
History
159 lines (136 loc) 路 3.51 KB

File metadata and controls

159 lines (136 loc) 路 3.51 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
namespace UUIDBenchmarks
{
[RankColumn]
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[SimpleJob(RuntimeMoniker.HostProcess, launchCount: 1, warmupCount: 2, iterationCount: 3)]
public class UUIDBenchmarks
{
private readonly long[] _longResults = new long[1000];
private readonly UUID[] _uuids = new UUID[1000];
private readonly byte[] _buffer = new byte[16];
private readonly Guid _guid = Guid.NewGuid();
private readonly UUID _uuid2 = UUID.New();
private readonly UUID _uuid = UUID.New();
private readonly string _uuidString;
public UUIDBenchmarks()
{
_uuidString = _uuid.ToString();
}
[GlobalSetup]
public void Setup()
{
for (int i = 0; i < _uuids.Length; i++)
{
_uuids[i] = UUID.New();
}
}
[Benchmark(Baseline = true)]
public UUID Generate_New()
{
return UUID.New();
}
[Benchmark]
public string Convert_ToString()
{
return _uuid.ToString();
}
[Benchmark]
public UUID Parse_FromString()
{
return UUID.Parse(_uuidString);
}
[Benchmark]
public bool TryParse_FromString()
{
return UUID.TryParse(_uuidString, out _);
}
[Benchmark]
public string Convert_ToBase32()
{
return _uuid.ToBase32();
}
[Benchmark]
public string Convert_ToBase64()
{
return _uuid.ToBase64();
}
[Benchmark]
public byte[] Convert_ToByteArray()
{
return _uuid.ToByteArray();
}
[Benchmark]
public bool Convert_TryWriteBytes()
{
return _uuid.TryWriteBytes(_buffer);
}
[Benchmark]
public bool Convert_TryWriteStringify()
{
char[] buffer = new char[32];
return _uuid.TryWriteStringify(buffer);
}
[Benchmark]
public Guid Convert_ToGuid()
{
return _uuid.ToGuid();
}
[Benchmark]
public UUID Convert_FromGuid()
{
return UUID.FromGuid(_guid);
}
[Benchmark]
public Guid Convert_ToGuid_Implicit()
{
return _uuid;
}
[Benchmark]
public UUID Convert_FromGuid_Implicit()
{
return _guid;
}
[Benchmark]
public bool Compare_Equals()
{
return _uuid.Equals(_uuid2);
}
[Benchmark]
public int Compare_CompareTo()
{
return _uuid.CompareTo(_uuid2);
}
[Benchmark]
public bool Compare_LessThan()
{
return _uuid < _uuid2;
}
[Benchmark]
public bool Compare_GreaterThan()
{
return _uuid > _uuid2;
}
[Benchmark]
public long ToInt64_SingleUUID()
{
return _uuid.ToInt64();
}
[Benchmark]
public long ImplicitToInt64_SingleUUID()
{
return (long)_uuid;
}
[Benchmark]
public void ToInt64_MultipleUUIDs()
{
for (int i = 0; i < _uuids.Length; i++)
{
_longResults[i] = _uuids[i].ToInt64();
}
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.