-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathBinaryWriterExtendedTests.cs
43 lines (36 loc) · 1.08 KB
/
BinaryWriterExtendedTests.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
// 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 BinaryWriterExtendedTests
{
private string _input;
private char[] _inputAsChars;
private BinaryWriter _bw;
[Params(32, 8_000, 2_000_000)]
public int StringLengthInChars;
[GlobalSetup]
public void Setup()
{
_bw = new BinaryWriter(new NullWriteStream());
_input = new string('x', StringLengthInChars);
_inputAsChars = _input.ToCharArray();
}
[Benchmark]
[MemoryRandomization]
public void WriteAsciiCharArray()
{
_bw.Write(_inputAsChars);
}
[Benchmark]
[MemoryRandomization]
public void WriteAsciiString()
{
_bw.Write(_input);
}
}
}