Skip to content

Commit e85f2a0

Browse files
committed
Update Readme.md
1 parent 88f680e commit e85f2a0

1 file changed

Lines changed: 60 additions & 51 deletions

File tree

Readme.md

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,83 +74,62 @@ BenchmarkRunner.Run<MyBenchmarks>(configuration);
7474
7575
## Application-level benchmarks
7676

77-
Benchmark Revit applicationlevel operations:
77+
Benchmark Revit application-level operations:
7878

7979
```csharp
8080
using BenchmarkDotNet.Attributes;
8181

8282
public class RevitApplicationBenchmarks : RevitApiBenchmark
8383
{
8484
[Benchmark]
85-
public double Create_XYZ_Distance()
85+
public XYZ NewXyz()
8686
{
87-
var point = Application.Create.NewXYZ(3, 4, 5);
88-
return point.DistanceTo(XYZ.Zero);
87+
return new XYZ(3, 4, 5);
88+
}
89+
90+
[Benchmark]
91+
public XYZ CreateNewXyz()
92+
{
93+
return Application.Create.NewXYZ(3, 4, 5);
8994
}
9095
}
9196
```
9297

93-
## Benchmarks using global hooks
98+
## Document benchmarks
9499

95-
BenchmarkDotNet provides **[GlobalSetup]** and **[GlobalCleanup]** hooks, but due to library limitations, it cannot be assigned twice.
96-
If you need these hooks in your benchmarks, for example to open the Document, use `OnGlobalSetup`/`OnGlobalCleanup` overrides instead:
100+
Use `OnGlobalSetup` and `OnGlobalCleanup` overrides to open and close a document around benchmark iterations.
101+
BenchmarkDotNet provides `[GlobalSetup]` and `[GlobalCleanup]` hooks, but due to library limitations, they cannot be assigned twice:
97102

98103
```csharp
99104
using BenchmarkDotNet.Attributes;
100105

101-
public class RevitDocumentBenchmarks : RevitApiBenchmark
106+
public class RevitCollectorBenchmarks : RevitApiBenchmark
102107
{
103-
private Document _documentFile = null!;
108+
private Document _document = null!;
104109

105110
protected sealed override void OnGlobalSetup()
106111
{
107-
_documentFile = Application.OpenDocumentFile($@"C:\Program Files\Autodesk\Revit {Application.VersionNumber}\Samples\rac_basic_sample_family.rfa");
108-
}
109-
110-
protected sealed override void OnGlobalCleanup()
111-
{
112-
_documentFile.Close(false);
112+
_document = Application.NewProjectDocument(UnitSystem.Metric);
113113
}
114114

115-
[Benchmark]
116-
public IList<Element> WhereElementIsElementTypeToElements()
115+
protected sealed override void OnGlobalCleanup()
117116
{
118-
return new FilteredElementCollector(_documentFile)
119-
.WhereElementIsElementType()
120-
.ToElements();
117+
_document.Close(false);
121118
}
122119

123120
[Benchmark]
124-
public IList<Element> ElementIsElementTypeFilterToElements()
121+
public IList<Element> WhereElementIsNotElementTypeToElements()
125122
{
126-
return new FilteredElementCollector(_documentFile)
127-
.WherePasses(new ElementIsElementTypeFilter())
123+
return new FilteredElementCollector(_document)
124+
.WhereElementIsNotElementType()
128125
.ToElements();
129126
}
130127

131128
[Benchmark]
132-
public List<Element> WhereElementIsElementTypeToList()
133-
{
134-
return new FilteredElementCollector(_documentFile)
135-
.WhereElementIsElementType()
136-
.ToList();
137-
}
138-
139-
[Benchmark]
140-
public List<ElementType> WhereElementIsElementTypeCastToList()
129+
public List<Element> WhereElementIsNotElementTypeToList()
141130
{
142-
return new FilteredElementCollector(_documentFile)
143-
.WhereElementIsElementType()
144-
.Cast<ElementType>()
145-
.ToList();
146-
}
147-
148-
[Benchmark]
149-
public List<ElementType> WhereElementIsElementTypeOfTypeToList()
150-
{
151-
return new FilteredElementCollector(_documentFile)
152-
.WhereElementIsElementType()
153-
.OfType<ElementType>()
131+
return new FilteredElementCollector(_document)
132+
.WhereElementIsNotElementType()
154133
.ToList();
155134
}
156135
}
@@ -168,10 +147,40 @@ Job=MediumRun BuildConfiguration=Release.R26 IterationCount=15
168147
LaunchCount=2 WarmupCount=10
169148
170149
```
171-
| Method | Mean | Error | StdDev | Allocated |
172-
|---------------------------------------|---------:|--------:|---------:|----------:|
173-
| WhereElementIsElementTypeToElements | 122.0 μs | 4.54 μs | 6.80 μs | 5.55 KB |
174-
| ElementIsElementTypeFilterToElements | 412.0 μs | 7.52 μs | 11.26 μs | 5.71 KB |
175-
| WhereElementIsElementTypeToList | 122.1 μs | 2.84 μs | 4.17 μs | 5.7 KB |
176-
| WhereElementIsElementTypeCastToList | 122.6 μs | 2.41 μs | 3.45 μs | 5.76 KB |
177-
| WhereElementIsElementTypeOfTypeToList | 122.0 μs | 2.19 μs | 3.20 μs | 5.76 KB |
150+
| Method | Mean | Error | StdDev | Allocated |
151+
|------------------------------------------|---------:|----------:|----------:|----------:|
152+
| WhereElementIsNotElementTypeToElements | 2.203 ms | 0.0494 ms | 0.1440 ms | 295.05 KB |
153+
| WhereElementIsNotElementTypeToList | 2.190 ms | 0.0436 ms | 0.0929 ms | 310.09 KB |
154+
155+
## Benchmark configuration
156+
157+
BenchmarkDotNet initializes Revit with the `English - United States` language and the `C:\Program Files\Autodesk\Revit {version}` installation path. To override these defaults, use assembly-level attributes:
158+
159+
- Add the attributes to any .cs file in your project (e.g., Program.cs):
160+
161+
```csharp
162+
using Nice3point.Revit.Injector.Attributes;
163+
164+
[assembly: RevitLanguage("ENU")]
165+
[assembly: RevitInstallationPath("D:\Autodesk\Revit Preview")]
166+
```
167+
168+
- Add the attributes directly to your .csproj file:
169+
170+
```xml
171+
<!-- Revit Environment Configuration -->
172+
<ItemGroup>
173+
174+
<AssemblyAttribute Include="Nice3point.Revit.Injector.Attributes.RevitLanguageAttribute">
175+
<_Parameter1>ENU</_Parameter1>
176+
</AssemblyAttribute>
177+
178+
<AssemblyAttribute Include="Nice3point.Revit.Injector.Attributes.RevitInstallationPathAttribute">
179+
<_Parameter1>D:\Autodesk\Revit $(RevitVersion)</_Parameter1>
180+
</AssemblyAttribute>
181+
182+
</ItemGroup>
183+
```
184+
185+
The `RevitLanguage` attribute accepts a [language](https://help.autodesk.com/view/RVT/2026/ENU/?guid=GUID-BD09C1B4-5520-475D-BE7E-773642EEBD6C) name (e.g., "English - United States"), code (e.g., "ENU")
186+
or [LanguageType](https://www.revitapidocs.com/2026/dfda33cf-cbff-9fde-6672-38402e87510f.htm) enum value (e.g., "English_GB" or "15").

0 commit comments

Comments
 (0)