-
Notifications
You must be signed in to change notification settings - Fork 272
/
Perf.XDocument.cs
49 lines (40 loc) · 1.51 KB
/
Perf.XDocument.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
// 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.Xml.Linq
{
[BenchmarkCategory(Categories.Libraries)]
public class Perf_XDocument
{
private XDocument _doc;
private XElement _root;
[Benchmark]
public XDocument Create() => new XDocument();
[Benchmark]
public XDocument Parse()
{
return XDocument.Parse("<elem1 child1='' child2='duu' child3='e1;e2;' child4='a1' child5='goody'> some xml element content </elem1>");
}
[GlobalSetup(Target = nameof(CreateWithRootlEement))]
public void SetupRootElement()
{
_root = new XElement("Root", "some xml element content");
}
[Benchmark]
public XDocument CreateWithRootlEement()
{
return new XDocument(_root);
}
[GlobalSetup(Targets = new[] { nameof(GetRootElement), nameof(GetElement) })]
public void SetupGetRootElement()
{
_doc = XDocument.Parse("<elem1 child1='' child2='duu' child3='e1;e2;' child4='a1' child5='goody'> some xml element content <elem2>Hello</elem2></elem1>");
}
[Benchmark]
public XElement GetRootElement() => _doc.Root;
[Benchmark]
public XElement GetElement() => _doc.Element("elem2");
}
}