Skip to content

Commit 8f868dd

Browse files
committed
[Benchmarks] Refactor benchmarks: rename classes, update setup logic, and add memory diagnoser
1 parent 440dfc7 commit 8f868dd

5 files changed

Lines changed: 78 additions & 66 deletions

File tree

Nice3point.BenchmarkDotNet.Revit.Tests/RevitApplicationBenchmarks.cs renamed to Nice3point.BenchmarkDotNet.Revit.Tests/ApplicationBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace Nice3point.BenchmarkDotNet.Revit.Tests;
44

5-
[MemoryDiagnoser]
6-
public class RevitApplicationBenchmarks : RevitApiBenchmark
5+
public class ApplicationBenchmarks : RevitApiBenchmark
76
{
87
[Benchmark]
98
public XYZ NewXyz()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
namespace Nice3point.BenchmarkDotNet.Revit.Tests;
4+
5+
public class CollectorBenchmarks : RevitApiBenchmark
6+
{
7+
private Document _document = null!;
8+
9+
protected sealed override void OnGlobalSetup()
10+
{
11+
_document = Application.NewProjectDocument(UnitSystem.Metric);
12+
13+
using var transaction = new Transaction(_document, "Seed model");
14+
transaction.Start();
15+
16+
var level = Level.Create(_document, 0);
17+
for (var i = 0; i < 1000; i++)
18+
{
19+
Wall.Create(_document, Line.CreateBound(new XYZ(i, 0, 0), new XYZ(i + 1, 0, 0)), level.Id, false);
20+
}
21+
22+
transaction.Commit();
23+
}
24+
25+
protected sealed override void OnGlobalCleanup()
26+
{
27+
_document.Close(false);
28+
}
29+
30+
[Benchmark]
31+
public IList<Element> WhereElementIsNotElementTypeToElements()
32+
{
33+
return new FilteredElementCollector(_document)
34+
.WhereElementIsNotElementType()
35+
.ToElements();
36+
}
37+
38+
[Benchmark]
39+
public IList<Element> ElementIsElementTypeFilterToElements()
40+
{
41+
return new FilteredElementCollector(_document)
42+
.WherePasses(new ElementIsElementTypeFilter(true))
43+
.ToElements();
44+
}
45+
46+
[Benchmark]
47+
public List<Element> WhereElementIsNotElementTypeToList()
48+
{
49+
return new FilteredElementCollector(_document)
50+
.WhereElementIsNotElementType()
51+
.ToList();
52+
}
53+
54+
[Benchmark]
55+
public List<Wall> WhereElementIsNotElementTypeCastToList()
56+
{
57+
return new FilteredElementCollector(_document)
58+
.WhereElementIsNotElementType()
59+
.OfClass(typeof(Wall))
60+
.Cast<Wall>()
61+
.ToList();
62+
}
63+
64+
[Benchmark]
65+
public List<Wall> WhereElementIsNotElementTypeOfTypeToList()
66+
{
67+
return new FilteredElementCollector(_document)
68+
.WhereElementIsNotElementType()
69+
.OfClass(typeof(Wall))
70+
.OfType<Wall>()
71+
.ToList();
72+
}
73+
}

Nice3point.BenchmarkDotNet.Revit.Tests/Nice3point.BenchmarkDotNet.Revit.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<EnableTUnitPolyfills>false</EnableTUnitPolyfills>
65
<Configurations>Debug.R21;Debug.R22;Debug.R23;Debug.R24;Debug.R25;Debug.R26;Debug.R27</Configurations>
76
<Configurations>$(Configurations);Release.R21;Release.R22;Release.R23;Release.R24;Release.R25;Release.R26;Release.R27</Configurations>
87
</PropertyGroup>
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Diagnosers;
23
using BenchmarkDotNet.Jobs;
34
using BenchmarkDotNet.Running;
45
using Nice3point.BenchmarkDotNet.Revit;
56
using Nice3point.BenchmarkDotNet.Revit.Tests;
67

78
var configuration = ManualConfig.Create(DefaultConfig.Instance)
8-
.AddJob(Job.Default.WithCurrentConfiguration());
9+
.AddJob(Job.Default.WithCurrentConfiguration())
10+
.AddDiagnoser(MemoryDiagnoser.Default);
911

10-
BenchmarkRunner.Run<RevitCollectorBenchmarks>(configuration);
12+
BenchmarkRunner.Run<CollectorBenchmarks>(configuration);

Nice3point.BenchmarkDotNet.Revit.Tests/RevitCollectorBenchmarks.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)