-
Notifications
You must be signed in to change notification settings - Fork 272
/
Perf.Guids.cs
57 lines (46 loc) · 1.56 KB
/
Perf.Guids.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
// 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 System.Buffers;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace System.Text.Json.Tests
{
[BenchmarkCategory(Categories.Libraries, Categories.JSON)]
public class Perf_Guids
{
private const int DataSize = 100_000;
private ArrayBufferWriter<byte> _arrayBufferWriter;
private Guid[] _guidArrayValues;
[Params(true, false)]
public bool Formatted;
[Params(true, false)]
public bool SkipValidation;
[GlobalSetup]
public void Setup()
{
_arrayBufferWriter = new ArrayBufferWriter<byte>();
_guidArrayValues = new Guid[DataSize];
for (int i = 0; i < DataSize; i++)
{
_guidArrayValues[i] = new Guid();
}
}
[Benchmark]
[MemoryRandomization]
public void WriteGuids()
{
_arrayBufferWriter.Clear();
using (var json = new Utf8JsonWriter(_arrayBufferWriter, new JsonWriterOptions { Indented = Formatted, SkipValidation = SkipValidation }))
{
json.WriteStartArray();
for (int i = 0; i < DataSize; i++)
{
json.WriteStringValue(_guidArrayValues[i]);
}
json.WriteEndArray();
json.Flush();
}
}
}
}