# Benchmark Framework
## Table of Contents
- [Overview and Features](#overview-and-features)
- [Using the Framework](#using-the-framework)
- [Attribute Summary](#attribute-summary)
- [Example](#example)
- [Glue Layer - Native Containers](#glue-layer---native-containers)
- [Performance and Benchmark Tests - Native Containers](#performance-and-benchmark-tests---native-containers)
- [Results](#results)
## Overview and Features
The Benchmark Framework is a complimentary framework to the Performance Test Framework. It provides a means to write a code for performance tests *one time* for a given type while providing the following benefits:
- Both benchmarks comparisons and performance/regression testing from a single implementation
- A managed execution path (JIT) from the same single implementation
- A Burst compiled *with safety* path from the same single implementation
- A Burst compiled *without safety* path from the same single implementation
- Automatically generate markdown formatted documentation for the Benchmark results
- Provide a simple means for running benchmarks through custom menu items with easily trackable progress and ability to cancel at any time
For the Benchmark Framework itself, tests can be designed to easily group together multiple variations for comparison. For example, the list above may apply to:
- An implementation for Native containers
- Another implementation for Unsafe containers
- And yet another implementation for the container types included in .NET/Mono/IL2CPP Base Class Libraries
Finally, test implementations may be classified such as:
- Only test for benchmarking, but not for performance/regression testing (such as managed BCL containers)
- Consider an implementation variation as the baseline, and compare all other implementation variations against it
- Include only a subset of implementation in case there is a gap in functionality (intentional or not) at this time
<br/>
---
## Using the Framework
To take advantage of the features above and write tests for the Benchmark Framework, three components are required:
1. The Benchmark Framework itself which works alongside the Performance Test Framework
2. An intermediate 'glue' layer for a given benchmark comparison type i.e. BenchmarkContainer, BenchmarkAllocator
3. The Performance Tests themselves, using the intermediate layer from #2 above
Because #1 is provided by the Framework here, the rest of this documentation will give an example of using it to create a 'glue' layer and then a performance test which makes use of this example 'glue' layer.
### Attribute Summary
Most (but not *quite* all) interaction with the Benchmark Framework will occur through its attributes. These are all defined in the `Unity.PerformanceTesting.Benchmark` namespace. A summary will be given here, but further details can be found in the inline code documentation. As mentioned, a small example demonstrating their use will follow.
|Attribute|Description|
|---|---|
|**`[Benchmark]`**|This marks a class containing performance tests to be used in Benchmark Comparison report generation.|
|**`[BenchmarkComparison]`**|This marks an enum as defining the variants that will be generated and simultaneously covers both the Performance Test Framework tests as well as Benchmark Framework tests. *Optionally, this can define the Benchmark baseline if it is also a Performance Test Framework measurement.*|
|**`[BenchmarkComparisonExternal]`**|Used on the same enum definition, this associates non-enum values with the enum for Benchmark Framework tests which *are not* to be included in Performance Test Framework tests. *Optionally, this can define the Benchmark baseline if it is not a Performance Test Framework measurement.*|
|**`[BenchmarkComparisonDisplay]`**|Also used on the same enum definition, this overrides the default measurement sample unit (millisecond, microsecond, etc.), the decimal places for Benchmark report generation, and the ranking statistic for Benchmark report generation (median, minimum, etc.).|
|**`[BenchmarkName]`**|Required with each enum value, this describes a formatting string for naming Benchmark result variations when a report is generated, such as `[BenchmarkName("Native{0}")]`, which when used with a `[Benchmark]` attributed class such as `HashSet`, would generate a the name "NativeHashSet"|
|**`[BenchmarkNameOverride]`**|Override the formatted name in case the class doesn't precisely represent the name that should appear in reports.|
|**`[BenchmarkTestFootnote]`**|Generate a footnote in the Benchmark Comparison report for a given Performance Test method. When used, the footnote will always include a description of the method and its parameters. Optionally, user-defined footnote text may be specified as well.|
Generally, `[Benchmark]`, `[BenchmarkNameOverride]`, and `[BenchmarkTestFootnote]` will be used while writing tests. The rest are used solely in the 'glue' layer, so if you are writing tests on top of a pre-existing 'glue' layer, you will be unlikely to need or use them.
<br/>
---
## Example
### Glue Layer - Native Containers
This will illustrate a simplified version of the com.unity.collections `BenchmarkContainer` implementation as an example of creating an intermediate 'glue' layer between the Benchmark Framework and user-defined performance tests.
1. The first requirement is an `enum` type which defines the test variations that will be benchmarked. Values defined in the enum will also generate Performance Test Framework tests used in regression testing and performance analysis. Values defined through the `[BenchmarkComparison]` attribute will only appear in Benchmark reports.<br/><br/>
You'll notice two attributes used. `[BenchmarkComparison]` denotes this `enum` will be used for benchmarking as well as indicates an externally defined comparison type (BCL) as the baseline to benchmark against, and `[BenchmarkComparisonDisplay]` overrides the default format for report generation and the statistic used for comparison.<br/><br/>
It's worth pointing out that the `{0}` in the name strings will be replaced with the name of the test group, such as `HashSet` or `List`. This also references a `MyExampleConfig` for convenience and consistency which will be defined next.
```
[BenchmarkComparison(MyExampleConfig.BCL, "{0} (BCL)")]
[BenchmarkComparisonDisplay(SampleUnit.Millisecond, 3, BenchmarkRankingStatistic.Median)]
public enum MyExampleType : int
{
[BenchmarkName("Native{0}")] Managed,
[BenchmarkName("Native{0} (B)")] BurstCompiled,
}
```
2. The configuration class is not a requirement, but rather it is a recommended pattern for storing common data for all tests as well as the interface (in this case a menu item) for running benchmarks and generating the resulting markdown file.<br/><br/>
The main takeaway here is the call to `GenerateMarkdown` which also runs the benchmark tests. Specifically, the argument `typeof(MyExampleType)` refers to the above defined comparison `enum`, and this call will find all the types with a `[Benchmark(typeof(MyExampleType))]` attribute and their methods with the combined `[Test]` and `[Performance]` attributes discover and run benchmark tests. More on this later with the example performance tests which will be benchmarked.
```
public static class MyExampleConfig
{
public const int BCL = -1;
internal const int kCountWarmup = 5;
internal const int kCountMeasure = 10;
#if UNITY_EDITOR
[UnityEditor.MenuItem("Benchmark Example/Generate My Benchmarks")]
#endif
static void RunBenchmarks() =>
BenchmarkGenerator.GenerateMarkdown(
"Containers Example",
typeof(MyExampleType),
"Temp/performance-comparison-example.md",
$"Example benchmark - {kCountMeasure} runs after {kCountWarmup} warmup runs",
"Legend",
new string[]
{
没有合适的资源?快使用搜索试试~ 我知道了~
CSDN帖子【AI学习笔记】基于Unity+DeepSeek开发的一些BUG记录&解决方案:https://blog.csdn.net/bailichen800/article/details/142655426?sharetype=blogdetail&sharerId=142655426&sharerefer=PC&sharesource=bailichen800&spm=1011.2480.3001.8118
存在一些不完善的地方和BUG,请结合博客链接谨慎参考。
收起资源包目录
Unity&DeepSeek开发简易AI对话助手 (2000个子文件)
LiberationSans SDF.asset 2.15MB
Unity SDF.asset 2.01MB
ProjectSettings.asset 25KB
EmojiOne.asset 13KB
DropCap Numbers.asset 10KB
InputManager.asset 10KB
LiberationSans SDF - Fallback.asset 9KB
Electronic Highway Sign SDF.asset 8KB
Roboto-Bold SDF.asset 8KB
Oswald Bold SDF.asset 8KB
Anton SDF.asset 8KB
Bangers SDF.asset 8KB
Default Sprite Asset.asset 8KB
Default Style Sheet.asset 5KB
QualitySettings.asset 4KB
GraphicsSettings.asset 3KB
Physics2DSettings.asset 2KB
TMP Settings.asset 2KB
EditorSettings.asset 1KB
NavMeshAreas.asset 1KB
DynamicsManager.asset 1KB
MemorySettings.asset 1KB
Readme.asset 1KB
PackageManagerSettings.asset 1003B
UnityConnectSettings.asset 943B
TagManager.asset 657B
Dark to Light Green - Vertical.asset 609B
Blue to Purple - Vertical.asset 588B
Light to Dark Green - Vertical.asset 585B
Yellow to Orange - Vertical.asset 544B
ShaderGraphSettings.asset 524B
AudioManager.asset 413B
URPProjectSettings.asset 410B
EditorBuildSettings.asset 401B
VFXManager.asset 308B
TimeManager.asset 202B
VersionControlSettings.asset 188B
XRSettings.asset 158B
MultiplayerManager.asset 157B
PresetManager.asset 146B
ClusterInputManager.asset 114B
Assembly-CSharp-Editor.csprojAssemblyReference.cache 309KB
Assembly-CSharp.csprojAssemblyReference.cache 303KB
DesignTimeResolveAssemblyReferencesInput.cache 41KB
TMPro_Mobile.cginc 5KB
TMPro_Surface.cginc 3KB
TMPro_Properties.cginc 3KB
TMPro.cginc 2KB
packages.config 144B
COMIntegration.cpp 14KB
TMP_TextEventHandler.cs 9KB
TMP_TextSelector_A.cs 7KB
ReadmeEditor.cs 7KB
Benchmark01_UGUI.cs 4KB
TMPro_InstructionOverlay.cs 3KB
Benchmark04.cs 3KB
TextMeshSpawner.cs 3KB
TMP_TextEventCheck.cs 3KB
TMP_ExampleScript_01.cs 2KB
Readme.cs 302B
NugetForUnity.dll 219KB
NuGetForUnity.PluginAPI.dll 9KB
ComPtr.h 3KB
BStrHolder.h 416B
SDFFunctions.hlsl 6KB
Sunny Days - Seamless.jpg 267KB
Floor Tiles 1 - diffuse.jpg 152KB
Fruit Jelly (B&W).jpg 147KB
Small Crate_normal.jpg 124KB
Small Crate_diffuse.jpg 93KB
Floor Cement.jpg 70KB
Brushed Metal 3.jpg 28KB
Gradient Diagonal (Color).jpg 11KB
Gradient Horizontal (Color).jpg 11KB
Gradient Vertical (Color).jpg 11KB
1900b0aEDbg.dag.json 12.59MB
1900b0aEDbg-inputdata.json 2.54MB
tundra.log.json 554KB
fullprofile.json 315KB
ProjectWideActionsTemplate.json 40KB
PackageConversionData.json 27KB
ProductionReadySamplesDescriptions.json 25KB
FeatureExamplesDescriptions.json 19KB
projectResolution.json 18KB
package.json 12KB
packages-lock.json 12KB
PackageConversionData_Assets.json 8KB
package.json 6KB
EmojiOne.json 4KB
UI_Default_Sprites_Default_5_0.5.json 4KB
UI_Default_Sprites_Default_5_0.json 4KB
SceneTemplateSettings.json 3KB
package.json 3KB
package.json 2KB
package.json 2KB
manifest.json 2KB
package.json 2KB
package.json 1KB
package.json 1KB
package.json 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源推荐
资源预览
资源评论
2024-04-15 上传
5星 · 资源好评率100%
5星 · 资源好评率100%
5星 · 资源好评率100%
2020-11-23 上传
2024-09-01 上传
5星 · 资源好评率100%
113 浏览量
2024-09-01 上传
2024-09-01 上传
2024-01-20 上传
149 浏览量
2024-09-01 上传
136 浏览量
5星 · 资源好评率100%
163 浏览量
5星 · 资源好评率100%
132 浏览量
2023-08-04 上传
5星 · 资源好评率100%
140 浏览量
2024-08-17 上传
5星 · 资源好评率100%
资源评论
百里香酚兰
- 粉丝: 497
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- springboot项目福泰轴承股份有限公司进销存系统.zip
- springboot项目房屋租赁管理系统boot.zip
- 淘宝购买的廉价232-USB串口线驱动,2011年CH340
- springboot项目防疫物资管理信息系统.zip
- springboot项目高校汉服租赁网站.zip
- springboot项目甘肃旅游服务平台代码.zip
- springboot项目高校毕业与学位资格审核系统_zpl.zip
- springboot项目高校科研信息管理系统.zip
- springboot项目高校教师教研信息填报系统.zip
- springboot项目高校竞赛管理系统.zip
- springboot项目高校危化试剂仓储系统.zip
- springboot项目高校物品捐赠管理系统.zip
- springboot项目高校实习管理系统.zip
- 人工智能与机器学习课程第六组期末作业,去雾模型改善了图像的纹理细节恢复与主观视觉质量
- springboot项目高校疫情防控web系统.zip
- springboot项目工资信息管理系统.zip
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功