-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathPerf.Environment.cs
49 lines (39 loc) · 1.78 KB
/
Perf.Environment.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 System.Collections;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace System.Tests
{
[BenchmarkCategory(Categories.Libraries)]
public class Perf_Environment
{
private const string Key = "7efd538f-dcab-4806-839a-972bc463a90c";
private const string ExpandedKey = "%" + Key + "%";
[GlobalSetup]
public void Setup() => Environment.SetEnvironmentVariable(Key, "value");
[GlobalCleanup]
public void Cleanup() => Environment.SetEnvironmentVariable(Key, null);
[Benchmark]
public string GetEnvironmentVariable() => Environment.GetEnvironmentVariable(Key);
[Benchmark]
public string ExpandEnvironmentVariables() => Environment.ExpandEnvironmentVariables(ExpandedKey);
[Benchmark]
public IDictionary GetEnvironmentVariables() => Environment.GetEnvironmentVariables();
[Benchmark]
[Arguments(Environment.SpecialFolder.System, Environment.SpecialFolderOption.None)]
[MemoryRandomization]
public void GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option)
=> Environment.GetFolderPath(folder, option);
[Benchmark]
[BenchmarkCategory(Categories.NoAOT)]
public string[] GetLogicalDrives() => Environment.GetLogicalDrives();
[Benchmark(OperationsPerInvoke = 2)]
public void SetEnvironmentVariable()
{
Environment.SetEnvironmentVariable(Key, "some value 1");
Environment.SetEnvironmentVariable(Key, "some value 2");
}
}
}