-
Notifications
You must be signed in to change notification settings - Fork 273
/
BinaryWriterTests.cs
81 lines (68 loc) · 1.68 KB
/
BinaryWriterTests.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace System.IO.Tests
{
[BenchmarkCategory(Categories.Libraries)]
public class BinaryWriterTests
{
private BinaryWriter _bw;
[GlobalSetup]
public void Setup()
{
_bw = new BinaryWriter(new NullWriteStream());
}
[Benchmark]
[MemoryRandomization]
public BinaryWriter DefaultCtor() => new BinaryWriter(Stream.Null);
[Benchmark]
public void WriteBool()
{
_bw.Write(true);
}
[Benchmark]
public void WriteAsciiChar()
{
_bw.Write('a');
}
[Benchmark]
public void WriteNonAsciiChar()
{
_bw.Write('\u00E0');
}
[Benchmark]
public void WriteUInt16()
{
_bw.Write((ushort)0xabcd);
}
[Benchmark]
public void WriteUInt32()
{
_bw.Write((uint)0xdeadbeef);
}
[Benchmark]
public void WriteUInt64()
{
_bw.Write((ulong)0xdeadbeef_aabbccdd);
}
#if NET5_0_OR_GREATER
[Benchmark]
public void WriteHalf()
{
_bw.Write((Half)3.14);
}
#endif
[Benchmark]
public void WriteSingle()
{
_bw.Write((float)Math.PI);
}
[Benchmark]
public void WriteDouble()
{
_bw.Write((double)Math.PI);
}
}
}