-
-
Notifications
You must be signed in to change notification settings - Fork 986
/
Copy pathDotMemoryTests.cs
75 lines (68 loc) · 2.5 KB
/
DotMemoryTests.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Diagnostics.dotMemory;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
using Xunit;
using Xunit.Abstractions;
namespace BenchmarkDotNet.IntegrationTests
{
public class DotMemoryTests : BenchmarkTestExecutor
{
public DotMemoryTests(ITestOutputHelper output) : base(output) { }
[Fact]
public void DotMemorySmokeTest()
{
if (!OsDetector.IsWindows() && RuntimeInformation.IsMono)
{
Output.WriteLine("Skip Mono on non-Windows");
return;
}
var config = new ManualConfig().AddJob(
Job.Dry.WithId("ExternalProcess"),
Job.Dry.WithToolchain(InProcessEmitToolchain.Instance).WithId("InProcess")
);
string snapshotDirectory = Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Artifacts", "snapshots");
if (Directory.Exists(snapshotDirectory))
Directory.Delete(snapshotDirectory, true);
CanExecute<Benchmarks>(config);
Output.WriteLine("---------------------------------------------");
Output.WriteLine("SnapshotDirectory:" + snapshotDirectory);
var snapshots = Directory.EnumerateFiles(snapshotDirectory)
.Where(filePath => Path.GetExtension(filePath).Equals(".dmw", StringComparison.OrdinalIgnoreCase))
.Select(Path.GetFileName)
.OrderBy(fileName => fileName)
.ToList();
Output.WriteLine("Snapshots:");
foreach (string snapshot in snapshots)
Output.WriteLine("* " + snapshot);
Assert.Equal(4, snapshots.Count);
}
[DotMemoryDiagnoser]
public class Benchmarks
{
[Benchmark]
public int Foo0()
{
var list = new List<object>();
for (int i = 0; i < 1000; i++)
list.Add(new object());
return list.Count;
}
[Benchmark]
public int Foo1()
{
var list = new List<object>();
for (int i = 0; i < 1000; i++)
list.Add(new object());
return list.Count;
}
}
}
}