This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1 @@
ValidationExceptions.json
@@ -0,0 +1,3 @@
# https://confluence.unity3d.com/pages/viewpage.action?spaceKey=DEV&title=Package+Specifics+-+UPM
ConfigurationValidation:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a5d815866ec304e56b03ec5cfc5f8b0a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ed2c1c145cb193d4d8987d3886bc12b4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,79 @@
using Unity.Collections;
using Unity.Jobs;
namespace Doc.CodeSamples.Collections.Tests
{
class AliasingExample
{
public void foo()
{
#region allocation_aliasing
NativeList<int> nums = new NativeList<int>(10, Allocator.TempJob);
nums.Length = 5;
// Create an array of 5 ints that aliases the content of the list.
NativeArray<int> aliasedNums = nums.AsArray();
// Modify the first element of both the array and the list.
aliasedNums[0] = 99;
// Only the original need be disposed.
nums.Dispose();
// Throws an ObjectDisposedException because disposing
// the original deallocates the aliased memory.
aliasedNums[0] = 99;
#endregion
}
public void foo2()
{
#region allocation_reinterpretation
NativeArray<int> ints = new NativeArray<int>(10, Allocator.Temp);
// Length of the reinterpreted array is 20
// (because it has two shorts per one int of the original).
NativeArray<short> shorts = ints.Reinterpret<int, short>();
// Modifies the first 4 bytes of the array.
shorts[0] = 1;
shorts[1] = 1;
int val = ints[0]; // val is 65537 (2^16 + 2^0)
// Like with other aliased collections, only the original
// needs to be disposed.
ints.Dispose();
// Throws an ObjectDisposedException because disposing
// the original deallocates the aliased memory.
shorts[0] = 1;
#endregion
}
public void foo3()
{
#region allocation_dispose_job
NativeArray<int> nums = new NativeArray<int>(10, Allocator.TempJob);
// Create and schedule a job that uses the array.
ExampleJob job = new ExampleJob { Nums = nums };
JobHandle handle = job.Schedule();
// Create and schedule a job that will dispose the array after the ExampleJob has run.
// Returns the handle of the new job.
handle = nums.Dispose(handle);
#endregion
}
}
struct ExampleJob : IJob
{
public NativeArray<int> Nums;
public void Execute()
{
throw new System.NotImplementedException();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 754bd1bfc77f45aea641971c9495f0f7
timeCreated: 1616748125
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using Unity.Collections;
using Unity.Jobs;
namespace Doc.CodeSamples.Collections.Tests
{
struct ExamplesCollections
{
public void foo()
{
#region parallel_writer
NativeList<int> nums = new NativeList<int>(1000, Allocator.TempJob);
// The parallel writer shares the original list's AtomicSafetyHandle.
var job = new MyParallelJob {NumsWriter = nums.AsParallelWriter()};
#endregion
}
#region parallel_writer_job
public struct MyParallelJob : IJobParallelFor
{
public NativeList<int>.ParallelWriter NumsWriter;
public void Execute(int i)
{
// A NativeList<T>.ParallelWriter can append values
// but not grow the capacity of the list.
NumsWriter.AddNoResize(i);
}
}
#endregion
public void foo2()
{
#region enumerator
NativeList<int> nums = new NativeList<int>(10, Allocator.Temp);
// Calculate the sum of all elements in the list.
int sum = 0;
var enumerator = nums.GetEnumerator();
// The first MoveNext call advances the enumerator to the first element.
// MoveNext returns false when the enumerator has advanced past the last element.
while (enumerator.MoveNext())
{
sum += enumerator.Current;
}
// The enumerator is no longer valid to use after the array is disposed.
nums.Dispose();
#endregion
}
#region read_only
public struct MyJob : IJob
{
// This array can only be read in the job.
[ReadOnly] public NativeArray<int> nums;
public void Execute()
{
// If safety checks are enabled, an exception is thrown here
// because the array is read only.
nums[0] = 100;
}
}
#endregion
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d9848a39deeb4ff9aa9e4cec03215a4b
timeCreated: 1616749165
@@ -0,0 +1,20 @@
{
"name": "Unity.Collections.DocCodeSamples",
"rootNamespace": "",
"references": [
"GUID:e0cd26848372d4e5c891c569017e11f1"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d1fecb7e41996c7468b18df518b721d9
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
* [Collections package](index.md)
* [Known issues](issues.md)
* [Collections overview](collections-overview.md)
* [Collection types](collection-types.md)
* [Parallel readers and writers](parallel-readers.md)
* [Use allocators to control unmanaged memory](allocation.md)
* [Allocator overview](allocator-overview.md)
* [Aliasing allocators](allocator-aliasing.md)
* [Rewindable allocator overview](allocator-rewindable.md)
* [Custom allocator overview](allocator-custom-define.md)
* [Use a custom allocator](allocator-custom-use.md)
* [Performance comparisons](performance-comparisons.md)
* [Allocator benchmarks](allocator-benchmarks.md)
* [Allocator performance comparison](performance-comparison-allocators.md)
* [Container performance comparison](performance-comparison-containers.md)
@@ -0,0 +1,17 @@
---
uid: collections-allocation
---
# Use allocators to control unmanaged memory
The Collections package allocates `Native-` and `Unsafe-` collections from unmanaged memory, which means that their existence is unknown to the garbage collector.
You are responsible for deallocating any unmanaged memory that you don't need. If you fail to deallocate large or multiple allocations, it can lead to wasting a lot of memory, which might slow down or crash your program.
|**Topic**|**Description**|
|---|---|
|[Allocator overview](allocator-overview.md)| Understand how to use an allocator to manage unmanaged memory.|
|[Aliasing allocators](allocator-aliasing.md)| Create aliases, which share memory allocations with another collection.|
| [Rewindable allocator overview](allocator-rewindable.md)| Understand rewindable allocators, which can pre-allocate memory.|
|[Custom allocator](allocator-custom-define.md)| Understand custom allocators, which you can create for specific memory allocation needs.|
|[Allocator benchmarks](allocator-benchmarks.md)| Compare the various allocators and inspect their performance benchmarks.|
@@ -0,0 +1,26 @@
# Aliasing allocators
An **alias** is a collection which doesn't have its own allocation but instead shares the allocation of another collection, in whole or in part. For example, you can create an `UnsafeList` that doesn't allocate its own memory but instead uses a `NativeList`'s allocation. Writing to this shared memory via the `UnsafeList` affects the content of the `NativeList`, and vice versa.
You don't need to dispose aliases, and calling `Dispose` on an alias does nothing. Once an original is disposed, you can no longer use the aliases of the original:
[!code-cs[allocation_aliasing](../DocCodeSamples.Tests/CollectionsAllocationExamples.cs#allocation_aliasing)]
Aliasing is useful for the following situations:
* Getting a collection's data in the form of another collection type without copying the data. For example, you can create an `UnsafeList` that aliases a `NativeArray`.
* Getting a subrange of a collection's data without copying the data. For example, you can create an UnsafeList that aliases a subrange of another list or array.
* [Array reinterpretation](#array-reinterpretation).
An `Unsafe-` collection can alias a `Native-` collection even though such cases undermine the safety checks. For example, if an `UnsafeList` aliases a `NativeList`, it's not safe to schedule a job that accesses one while also another job is scheduled that accesses the other, but the safety checks don't catch these cases.
## Array reinterpretation
A **reinterpretation** of an array is an alias of the array that reads and writes the content as a different element type. For example, a `NativeArray<int>` which reinterprets a `NativeArray<ushort>` shares the same bytes, but it reads and writes the bytes as an int instead of a ushort. This is because each int is 4 bytes while each ushort is 2 bytes. Each int corresponds to two ushorts, and the reinterpretation has half the length of the original.
[!code-cs[allocation_reinterpretation](../DocCodeSamples.Tests/CollectionsAllocationExamples.cs#allocation_reinterpretation)]
## Further information
* [Define a custom allocator](allocator-custom-define.md)
* [Rewindable allocators](allocator-rewindable.md)
@@ -0,0 +1,33 @@
# Allocator benchmarks
The Collections package has different allocators that you can use to manage memory allocations. The different allocators organize and track their memory in different ways. These are the allocators available:
* [Allocator.Temp](allocator-overview.md#allocatortemp): A fast allocator for short-lived allocations, which is created on every thread.
* [Allocator.TempJob](allocator-overview.md#allocatortempjob): A short-lived allocator, which must be deallocated within 4 frames of their creation.
* [Allocator.Persistent](allocator-overview.md#allocatorpersistent): The slowest allocator for indefinite lifetime allocations.
* [Rewindable allocator](allocator-rewindable.md): A custom allocator that's fast and thread safe, and can rewind and free all your allocations at one point.
The [Entities package](https://docs.unity3d.com/Packages/com.unity.entities@latest) has its own set of custom prebuilt allocators:
* [World update allocator](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html?subfolder=/manual/allocators-world-update.html): A double rewindable allocator that a world owns, which is fast and thread safe.
* [Entity command buffer allocator](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html?subfolder=/manual/allocators-entity-command-buffer.html): A rewindable allocator that an entity command buffer system owns and uses to create entity command buffers.
* [System group allocator](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html?subfolder=/manual/allocators-system-group.html): An optional double rewindable allocator that a component system group creates when setting its rate manager. It's for allocations in a system of fixed or variable rate system group that ticks at different rate from the world update.
For more information, see the Entities documentation on [Custom prebuilt allocators](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html?subfolder=/manual/allocators-custom-prebuilt.html).
## Allocator feature comparison
The different allocators have the following different features:
|**Allocator type**|**Custom Allocator**|**Need to create before use**|**Lifetime**|**Automatically freed allocations**|**Can pass to jobs**|**Min Allocation Alignment (bytes)**|
|---|---|---|---|---|---|---|
|[Allocator.Temp](allocator-overview.md#allocatortemp)|No|No|A frame or a job|Yes|No|64|
|[Allocator.TempJob](allocator-overview.md#allocatortempjob)|No|No|Within 4 frames of creation|No|Yes|16|
|[Allocator.Persistent](allocator-overview.md#allocatorpersistent)|No|No|Indefinite|No|Yes|16|
|[Rewindable allocator](allocator-rewindable.md)|Yes|Yes|Indefinite|No|Yes|64|
## Performance test results
The following performance tests compare Temp, TempJob, Persistent and rewindable allocators. Because the world update allocator, entity command buffer allocator, and system group allocator are rewindable allocators, their performance is reflected in the rewindable allocator test results. The allocators are tested in single thread cases and in multithread cases by scheduling allocations in jobs across all the cores.
For results, refer to the [Performance comparison of allocators](performance-comparison-allocators.md) documentation.
@@ -0,0 +1,95 @@
# Custom allocator overview
You can use a custom allocator for specific memory allocation needs. To create a custom allocator, it must contain an allocator handle of type [`AllocatorManager.AllocatorHandle`](xref:Unity.Collections.AllocatorManager.AllocatorHandle) and implement the interface, [`AllocatorManager.IAllocator`](xref:Unity.Collections.AllocatorManager.IAllocator). After you create a custom allocator, you need to register it in a global allocator table in [`AllocatorManager`](xref:Unity.Collections.AllocatorManager).
## Add the AllocatorManager.AllocatorHandle type to the custom allocator
A custom allocator must contain an allocator handle of type [`AllocatorManager.AllocatorHandle`](xref:Unity.Collections.AllocatorManager.AllocatorHandle). An allocator handle includes the following:
* `Version`: A 2 byte unsigned version number. Only the lower 15 bits are valid.
* `Index`: A 2 byte unsigned index of the global allocator table obtained during registration.
* Method to add a safety handle to the list of child safety handles of the allocator handle.
* Method to add a child allocator to the list of child allocators of the allocator handle.
* A rewind method to invalidate and unregister all the child allocators, invalidate all the child safety handles of the allocator handle, and increment the allocator handle' `Version` and `OfficialVersion`.
## Implement AllocatorManager.IAllocator interface
To define a custom allocator, you must implement the interface [`AllocatorManager.IAllocator`](xref:Unity.Collections.AllocatorManager.IAllocator) which includes:
* [`Function`](xref:Unity.Collections.AllocatorManager.IAllocator.Function): A property that gets the allocator function of delegate [`TryFunction`](xref:Unity.Collections.AllocatorManager.TryFunction). The allocator function can allocate, deallocate, and reallocate memory.
* [`Try`](xref:Unity.Collections.AllocatorManager.IAllocator.Try(Unity.Collections.AllocatorManager.Block@)): A method that the allocator function invokes to allocate, deallocate, or reallocate memory.
* [`Handle`](xref:Unity.Collections.AllocatorManager.IAllocator.Handle): A property that gets and sets the allocator handle which is of type [`AllocatorManager.AllocatorHandle`](xref:Unity.Collections.AllocatorManager.AllocatorHandle).
* [`ToAllocator`](xref:Unity.Collections.AllocatorManager.IAllocator.ToAllocator): A property that casts the allocator handle index to the enum `Allocator`.
* [`IsCustomAllocator`](xref:Unity.Collections.AllocatorManager.IAllocator.IsCustomAllocator): A property that checks whether the allocator is a custom allocator. An allocator is a custom allocator if its handle `Index` is larger or equal to [`AllocatorManager.FirstUserIndex`](xref:Unity.Collections.AllocatorManager.FirstUserIndex).
* [`IsAutoDispose`](xref:Unity.Collections.AllocatorManager.AllocatorHandle.IsAutoDispose): A property that checks whether the allocator is able to dispose individual allocations. True if disposing an individual allocation is a no-op.
Because `AllocatorManager.IAllocator` implements `IDisposable`, your custom allocator must implement the `Dispose` method.
The following is an example of how to set up the `IAllocator` interface and its required properties except the `Try` and `AllocatorFunction` method:
```c#
// A custom allocator must implement AllocatorManager.IAllocator interface
[BurstCompile(CompileSynchronously = true)]
internal struct ExampleCustomAllocator : AllocatorManager.IAllocator
{
// A custom allocator must contain AllocatorManager.AllocatorHandle
AllocatorManager.AllocatorHandle m_handle;
// Implement the Function property required by IAllocator interface
public AllocatorManager.TryFunction Function => AllocatorFunction;
// Implement the Handle property required by IAllocator interface
public AllocatorManager.AllocatorHandle Handle { get { return m_handle; } set { m_handle = value; } }
// Implement the ToAllocator property required by IAllocator interface
public Allocator ToAllocator { get { return m_handle.ToAllocator; } }
// Implement the IsCustomAllocator property required by IAllocator interface
public bool IsCustomAllocator { get { return m_handle.IsCustomAllocator; } }
// Implement the IsAutoDispose property required by IAllocator interface
// Allocations made by this example allocator are not automatically disposed.
// This implementation can be skipped because the default implementation of
// this property is false.
public bool IsAutoDispose { get { return false; } }
// Implement the Dispose method required by IDisposable interface because
// AllocatorManager.IAllocator implements IDisposable
public void Dispose()
{
// Make sure no memory leaks
Assert.AreEqual(0, m_allocationCount);
m_handle.Dispose();
}
}
```
The `Try` method tells a custom allocator how to allocate or deallocate memory. The following is an example of the`Try` method where a custom allocator allocates memory from `Allocator.Persistant`, initializes the allocated memory with a user configured value, and increments an allocation count. The custom allocator also decrements the allocation count when deallocating the allocated memory.
[!code-cs[Try method of allocate/deallocate memory](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-try)]
Example method `AllocatorFunction` below shows an allocator function of the custom allocator.
[!code-cs[Allocator function](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-allocator-function)]
## Global allocator table
The global allocator table in [`AllocatorManager`](xref:Unity.Collections.AllocatorManager) stores all the necessary information for custom allocators to work. When you instantiate a custom allocator, you must register the allocator in the global allocator table. The table stores the following information:
* A pointer to the custom allocator instance
* A pointer to the allocator function of the custom allocator instance
* The current official version of the custom allocator instance, lower 15 bits of a 2 byte unsigned integer value
* A list of child safety handles of native containers that are created using the custom allocator instance
* A list of child allocators that are allocated using the custom allocator instance
* A bit flag indicating whether the custom allocator is able to dispose individual allocations
## Custom allocator example
The following is an example of a custom allocator that has an `AllocatorManager.AllocatorHandle` and initializes the allocated memory with a user configured value and increments the allocation count. It also uses `AllocatorManager.TryFunction` to register the allocator on the global allocator table:
[!code-cs[Custom allocator example](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-example)]
## Further information
* [Use a custom allocator](allocator-custom-use.md)
@@ -0,0 +1,65 @@
# Use a custom allocator
Once you've [defined a custom allocator](allocator-custom-define.md), you can add it to your structure or class.
## Declare and create a custom allocator
The first step is to declare and create the custom allocator. You must do the following:
* Allocate memory to hold the custom allocator
* Register the allocator by adding an entry in a global allocator table
* Initialize the allocator if necessary.
The wrapper [`AllocatorHelper`](xref:Unity.Collections.AllocatorHelper`1) helps the process in creating a custom allocator. Examples are given below as how to declare and create a custom allocator defined in the [Example custom allocator](allocator-custom-define.md).
```c#
// Example user structure that contains the custom allocator
internal struct ExampleCustomAllocatorStruct
{
// Use AllocatorHelper to help creating the example custom alloctor
AllocatorHelper<ExampleCustomAllocator> customAllocatorHelper;
// Custom allocator property for accessibility
public ref ExampleCustomAllocator customAllocator => ref customAllocatorHelper.Allocator;
// Create the example custom allocator
void CreateCustomAllocator(AllocatorManager.AllocatorHandle backgroundAllocator, byte initialValue)
{
// Allocate the custom allocator from backgroundAllocator and register the allocator
customAllocatorHelper = new AllocatorHelper<ExampleCustomAllocator>(backgroundAllocator);
// Set the initial value to initialize the memory
customAllocator.Initialize(initialValue);
}
}
```
## Use a custom allocator to allocate memory
For `Native-` collection types, allocation from a custom allocator is similar to a classic allocator, except you must use [`CollectionHelper.CreateNativeArray`](xref:Unity.Collections.CollectionHelper.CreateNativeArray*) to create a `NativeArray` from a custom allocator and [`CollectionHelper.Dispose`](xref:Unity.Collections.CollectionHelper.Dispose*) to deallocate a `NativeArray` from a custom allocator.
For `Unsafe-` collection types, you must use [`AllocatorManager.Allocate`](xref:Unity.Collections.AllocatorManager.Allocate*) to allocate memory from a custom allocator and [`AllocatorManager.Free`](xref:Unity.Collections.AllocatorManager.Free*) to deallocate the memory.
When you use a custom allocator to create a `Native-` collection type, its safety handle is added to the list of child safety handles of the custom allocator. When you rewind the allocator handle of a custom allocator, it invalidates and unregisters all its child allocators, and invalidates all its child safety handles. For `Native-` collection types, the disposal safety checks throw an exception if the allocator handle has rewound.
The following example method `UseCustomAllocator` shows how to use a custom allocator to create and allocate native containers:
[!code-cs[Use custom allocator to allocate memory](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-use)]
## Dispose a custom allocator
To dispose a custom allocator, the following must happen:
* The custom allocator must rewind its allocator handle which invalidates and unregisters all the allocator handle's child allocators, and invalidates all its child safety handles.
* You must unregister the allocator
* You must dispose the memory used to store the allocator.
Example method `DisposeCustomAllocator` in the user structure shows how to dispose a custom allocator.
[!code-cs[Dispose a custom allocator](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-dispose)]
## Full example of a custom allocator
The following is a full example of how to use a custom allocator:
[!code-cs[Add a custom allocator in user structure](../Unity.Collections.Tests/AllocatorCustomTests.cs#allocator-custom-user-struct)]
@@ -0,0 +1,68 @@
# Allocator overview
An **allocator** governs unmanaged memory from which you can make allocations. Different allocators organize and track their memory in different ways. The Collections package includes the following allocators:
* [`Allocator.Temp`](#allocatortemp): The fastest allocator, for short-lived allocations. You can't pass this allocator to a job.
* [`Allocator.TempJob`](#allocatortempjob): A short-lived allocator that you can pass into jobs.
* [`Allocator.Persistent`](#allocatorpersistent): The slowest allocator for indefinite lifetime allocations. You can pass this allocator to a job.
## Allocator.Temp
Each frame, the main thread creates a Temp allocator which it deallocates in its entirety at the end of the frame. Each job also creates one Temp allocator per thread, and deallocates them in their entirety at the end of the job. Because a Temp allocator gets discarded as a whole, you don't need to manually deallocate Temp allocations, and doing so does nothing. The minimum alignment of Temp allocations is 64 bytes.
Temp allocations are only safe to use in the thread and the scope where they were allocated. While you can make Temp allocations within a job, you can't pass main thread Temp allocations into a job. For example, you can't pass a native array that's Temp allocated in the main thread into a job.
## Allocator.TempJob
You must deallocate `TempJob` allocations within 4 frames of their creation. The 4-frame limit provides some margin for allocations that need to persist across a few frames. The minimum alignment of `TempJob` allocations is 16 bytes.
If a `TempJob` allocation isn't disposed within 4 frames, Unity writes a warning message but the allocation remains valid. Unity doesn't automatically deallocate such allocation, and you must still explicitly dispose it in your code to free the memory.
Exceeding the 4-frame limit has the following consequences:
* **Performance degradation**: The `TempJob` allocator has a fixed memory pool. If long-lived allocations accumulate and exhaust this pool, subsequent allocations fall back to `Allocator.Persistent`, which is significantly slower.
* **Memory leak reports**: If allocations still exist when the `TempJob` allocator is disposed (for example, when the application exits), Unity reports them as memory leaks when [native leak detection](https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeLeakDetection.html) is enabled.
> [!NOTE]
> For `Native-` collection types, safety checks log warnings when a `TempJob` allocation exceeds 4 frames. For `Unsafe-` collection types, Unity doesn't perform safety checks, and doesn't log warnings even if an allocation exceeds 4 frames.
If your job or allocation might regularly exceed 4 frames, use `Allocator.Persistent` instead.
If you need an intermediate-lifetime allocator optimized for durations between `TempJob` and `Persistent`, consider using a [custom allocator](allocator-custom-define.md) or a [rewindable allocator](allocator-rewindable.md).
## Allocator.Persistent
Because Persistent allocations can remain indefinitely, safety checks can't detect if a Persistent allocation has outlived its intended lifetime. As such, you must deallocate a Persistent allocation when you no longer need it. The minimum alignment of Persistent allocations is 16 bytes.
## Deallocating an allocator
Each collection retains a reference to the allocator that allocated its memory. This is because you must specify the allocator to deallocate its memory.
* An `Unsafe-` collection's `Dispose` method deallocates its memory.
* A `Native-` collection's `Dispose` method deallocates its memory and frees the handles needed for safety checks.
* An enumerator's `Dispose` method does nothing. The method exists only to fulfill the `IEnumerator<T>` interface.
To dispose a collection after the jobs which need it have run, you can use the `Dispose(JobHandle)` method. This creates and schedules a job which disposes of the collection, and this new job takes the input handle as its dependency. Effectively, the method defers disposal until after the dependency runs:
[!code-cs[allocation_dispose_job](../DocCodeSamples.Tests/CollectionsAllocationExamples.cs#allocation_dispose_job)]
### IsCreated property
The `IsCreated` property of a collection is false only in the following cases:
* Immediately after creating a collection with its default constructor.
* After `Dispose` has been called on the collection.
>[!NOTE]
>You don't need to use a collection's default constructor. The constructor is only available because C# requires all structs have a public default constructor.
Calling `Dispose` on a collection sets `IsCreated` to false only for that struct, and not in any copies of the struct. `IsCreated` might still be true even after the collection's underlying memory is deallocated in the following situations:
* `Dispose` was called on a different copy of the struct.
* The underlying memory was deallocated via an [alias](allocator-aliasing.md).
## Additional resources
* [Aliasing allocators](allocator-aliasing.md)
* [Rewindable allocators](allocator-rewindable.md)
* [Define a custom allocator](allocator-custom-define.md)
@@ -0,0 +1,86 @@
# Rewindable allocator overview
A rewindable allocator is a [custom allocator](allocator-custom-define.md) that works in a similar way to a linear allocator. It's fast and thread safe. A rewindable allocator pre-allocates blocks of memory in advance.
When you request memory from a rewindable allocator, it selects a range of memory from its pre-allocated block and assigns it to use. The minimum alignment of rewindable allocations is 64 bytes. After it uses all the existing blocks of memory, the rewindable allocator allocates another block of memory.
It doubles the size of the new block until it reaches a maximum block size. When it reaches this point, the rewindable allocator adds the maximum block size to its previous block size to increase its block size linearly.
One advantage of rewindable allocator is that you don't need to free individual allocations. As its name implies, a rewindable allocator can rewind and free all your allocations at one point.
When you rewind an allocator, the allocator keeps the memory blocks that it used before to improve performance and disposes the rest of the blocks. When you request to free or dispose a memory allocation from a rewindable allocator, it's a no-op unless you set the enable block free flag of the rewindable allocator. When you set the flag to enable block free, the rewindable allocator rewinds a memory block when it frees the last allocation from the block.
## Declare and create a rewindable allocator
To create a rewindable allocator, you must do the following:
* Allocate memory to hold the rewindable allocator
* Add an entry in the global allocator table to register the allocator
* Pre-allocate the allocator's first memory block to initialize it.
You can use the wrapper [`AllocatorHelper`](xref:Unity.Collections.AllocatorHelper`1) to create a rewindable allocator.
The following example declares and creates a rewindable allocator:
```c#
// Example user structure
internal struct ExampleStruct
{
// Use AllocatorHelper to help creating a rewindable alloctor
AllocatorHelper<RewindableAllocator> rwdAllocatorHelper;
// Rewindable allocator property for accessibility
public ref RewindableAllocator RwdAllocator => ref rwdAllocatorHelper.Allocator;
// Create the rewindable allocator
void CreateRewindableAllocator(AllocatorManager.AllocatorHandle backgroundAllocator, int initialBlockSize, bool enableBlockFree = false)
{
// Allocate the rewindable allocator from backgroundAllocator and register the allocator
rwdAllocatorHelper = new AllocatorHelper<RewindableAllocator>(backgroundAllocator);
// Allocate the first memory block with initialBlockSize in bytes, and indicate whether
// to enable the rewindable allocator with individual block free through enableBlockFree
RwdAllocator.Initialize(initialBlockSize, enableBlockFree);
}
}
```
## Use a rewindable allocator to allocate memory
For `Native-` collection types, allocation from a rewindable allocator is similar to a classic allocator, except you must use [`CollectionHelper.CreateNativeArray`](xref:Unity.Collections.CollectionHelper.CreateNativeArray*) to create a `NativeArray` from a rewindable allocator. When you use a rewindable allocator to create a `Native-` collection type, its safety handle is added to the list of child safety handles of the rewindable allocator.
For `Unsafe-` collection types, you must use [`AllocatorManager.Allocate`](xref:Unity.Collections.AllocatorManager.Allocate*) to allocate memory from a rewindable allocator.
You don't need to dispose individual allocations. When all allocations aren't needed anymore, call the `Rewind` method of a rewindable allocator to free all its allocations. When you rewind the rewindable allocator, it invalidates and unregisters its child allocators, and invalidates all its child safety handles. For `Native-` collection types, the disposal safety checks throw an exception if the rewindable allocator has rewound.
This example method `UseRewindableAllocator` shows how to use a rewindable allocator to create and allocate native containers:
[!code-cs[Use rewindable allocator to allocate memory](../Unity.Collections.Tests/AllocatorRewindableTests.cs#allocator-rewindable-use)]
## Free all allocated memory of a rewindable allocator
When you `Rewind` the rewindable allocator, it performs the following operations:
* Invalidates and unregisters all the allocator handle's child allocators
* Invalidates all its child safety handles
The example method `FreeRewindableAllocator` shows how to Free all allocations from the rewindable allocator, with [`Rewind`](xref:Unity.Collections.RewindableAllocator.Rewind).
[!code-cs[Free all allocations from the rewindable allocator](../Unity.Collections.Tests/AllocatorRewindableTests.cs#allocator-rewindable-free)]
## Dispose a rewindable allocator
To dispose a rewindable allocator, you must do the following:
* Dispose all the memory blocks of the rewindable allocator from `Allocator.Persistant`.
* Unregister the allocator
* Dispose the memory used to store the allocator
The following example adds a method `DisposeRewindableAllocator`that disposes a rewindable allocator using [`Dispose`](xref:Unity.Collections.AllocatorHelper`1.Dispose):
[!code-cs[Dispose a rewindable allocator](../Unity.Collections.Tests/AllocatorRewindableTests.cs#allocator-rewindable-dispose)]
## Full example of a rewindable allocator
The following is a full example of how to use a rewindable allocator:
[!code-cs[Full example of a rewindable allocator](../Unity.Collections.Tests/AllocatorRewindableTests.cs#allocator-rewindable-example)]
@@ -0,0 +1,90 @@
# Collection types
The collection types in this package extend and compliment the collections available in the Unity engine. This section outlines some key collection types you might want to use in your jobs and Burst compiled code.
## Array-like types
The array-like types in this package extend the key array types in the [`UnityEngine.CoreModule`](https://docs.unity3d.com/ScriptReference/UnityEngine.CoreModule) namespace, which include [`Unity.Collections.NativeArray<T>`](xref:Unity.Collections.NativeArray`1) and [`Unity.Collections.NativeSlice<T>`](xref:Unity.Collections.NativeSlice`1). This package has the following array-like types:
|**Data structure**|**Description**|
|---|---|
|[`NativeList<T>`](xref:Unity.Collections.NativeList`1)| A resizable list. Has thread and disposal safety checks.|
|[`UnsafeList<T>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeList`1)| A resizable list.|
|[`UnsafePtrList<T>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafePtrList`1)| A resizable list of pointers.|
|[`NativeStream`](xref:Unity.Collections.NativeStream)| A set of append-only, untyped buffers. Has thread and disposal safety checks.|
|[`UnsafeStream`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeStream)| A set of append-only, untyped buffers.|
|[`UnsafeAppendBuffer`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer)| An append-only untyped buffer.|
|[`NativeQueue<T>`](xref:Unity.Collections.NativeQueue`1)| A resizable queue. Has thread and disposal safety checks.|
|[`NativeRingQueue<T>`](xref:Unity.Collections.NativeRingQueue`1)| A fixed-size circular buffer. Has disposal safety checks.|
|[`UnsafeRingQueue<T>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeRingQueue`1) | A fixed-size circular buffer.|
|[`FixedList32Bytes<T>`](xref:Unity.Collections.FixedList32Bytes`1)| A 32-byte list, which includes 2 bytes of overhead, so 30 bytes are available for storage. Max capacity depends upon `T`. `FixedList32Bytes<T>` has variants of larger sizes:<br/>- `FixedList64Bytes<T>`<br/>- `FixedList128Bytes<T>`<br/>- `FixedList512Bytes<T>`<br/>- `FixedList4096Bytes<T>`|
There aren't any multi-dimensional array types, but you can pack all the data into a single dimension. For example, for an `int[4][5]` array, use an `int[20]` array instead (because `4 * 5` is `20`).
Additionally, there are various extension methods in [`NativeArrayExtensions`](xref:Unity.Collections.NativeArrayExtensions), [`ListExtensions`](xref:Unity.Collections.ListExtensions), and [`NativeSortExtension`](xref:Unity.Collections.NativeSortExtension).
## Map and set types
Use these collection types in single threads when there is a low memory overhead:
|**Data structure**|**Description**|
|---|---|
|[`NativeHashMap<TKey, TValue>`](xref:Unity.Collections.NativeHashMap`2)| An unordered associative array of key-value pairs. Has thread and disposal safety checks.|
|[`UnsafeHashMap<TKey, TValue>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeHashMap`2)| An unordered associative array of key-value pairs.|
|[`NativeHashSet<T>`](xref:Unity.Collections.NativeHashSet`1)| A set of unique values. Has thread and disposal safety checks.|
| [`UnsafeHashSet<T>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeHashSet`1)| A set of unique values.|
Use these collection types in multithreaded situations, when there is a high memory overhead.
|**Data structure**|**Description**|
|---|---|
|[`NativeParallelHashMap<TKey, TValue>`](xref:Unity.Collections.NativeParallelHashMap`2)|An unordered associative array of key-value pairs. Has thread and disposal safety checks.|
|[`UnsafeParallelHashMap<TKey, TValue>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMap`2)|An unordered associative array of key value pairs.|
| [`NativeParallelHashSet<T>`](xref:Unity.Collections.NativeParallelHashSet`1)| A set of unique values. Has thread and disposal safety checks.|
| [`UnsafeParallelHashSet<T>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashSet`1)|A set of unique values.|
|[`NativeParallelMultiHashMap<TKey, TValue>`](xref:Unity.Collections.NativeParallelMultiHashMap`2)|An unordered associative array of key value pairs. The keys don't have to be unique. For example, two pairs can have equal keys. Has thread and disposal safety checks.|
|[`UnsafeParallelMultiHashMap<TKey, TValue>`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeParallelMultiHashMap`2)| An unordered associative array of key value pairs. The keys don't have to be unique. For example, two pairs can have equal keys.|
Additionally, there are various extension methods in [`NotBurstCompatible.Extensions`](xref:Unity.Collections.NotBurstCompatible.Extensions) and [`Unsafe.NotBurstCompatible.Extensions`](xref:Unity.Collections.LowLevel.Unsafe.NotBurstCompatible.Extensions).
## Bit arrays and bit fields
The following are arrays of bits:
|**Data structure**|**Description**|
|---|---|
|[`BitField32`](xref:Unity.Collections.BitField32)| A fixed-size array of 32 bits.|
|[`BitField64`](xref:Unity.Collections.BitField64 )| A fixed-size array of 64 bits.|
|[`NativeBitArray`](xref:Unity.Collections.NativeBitArray)| An arbitrary sized array of bits. Has thread and disposal safety checks.|
|[`UnsafeBitArray`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeBitArray)| An arbitrary-sized array of bits.|
## String types
The following are string types:
|**Data structure**|**Description**|
|---|---|
|[`NativeText`](xref:Unity.Collections.NativeText)| A UTF-8 encoded string. Mutable and resizable. Has thread and disposal safety checks.|
|[`UnsafeText`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeText)| A UTF-8 encoded string. Mutable and resizable.|
|[`FixedString32Bytes`](xref:Unity.Collections.FixedString32Bytes) | A 32-byte UTF-8 encoded string, including 3 bytes of overhead, so 29 bytes available for storage.|
|[`FixedString64Bytes`](xref:Unity.Collections.FixedString64Bytes)| A 64-byte UTF-8 encoded string, including 3 bytes of overhead, so 61 bytes available for storage.|
|[`FixedString128Bytes`](xref:Unity.Collections.FixedString128Bytes)| A 128-byte UTF-8 encoded string, including 3 bytes of overhead, so 125 bytes available for storage.|
|[`FixedString512Bytes`](xref:Unity.Collections.FixedString512Bytes)| A 512-byte UTF-8 encoded string, including 3 bytes of overhead, so 509 bytes available for storage.|
|[`FixedString4096Bytes`](xref:Unity.Collections.FixedString4096Bytes) | A 4096-byte UTF-8 encoded string, including 3 bytes of overhead, so 4093 bytes available for storage.|
There are further extension methods in [`FixedStringMethods`](xref:Unity.Collections.FixedStringMethods).
## Other types
|**Data structure**|**Description**|
|---|---|
|[`NativeReference<T>`](xref:Unity.Collections.NativeReference`1) | A reference to a single value. Functionally equivalent to an array of length 1. Has thread and disposal safety checks.|
|[`UnsafeAtomicCounter32`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeAtomicCounter32) | A 32-bit atomic counter.|
|[`UnsafeAtomicCounter64`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeAtomicCounter64) | A 64-bit atomic counter.|
## Enumerators
Most of the collections have a `GetEnumerator` method, which returns an implementation of `IEnumerator<T>`. The enumerator's `MoveNext` method advances its `Current` property to the next element:
[!code-cs[enumerator](../DocCodeSamples.Tests/CollectionsExamples.cs#enumerator)]
@@ -0,0 +1,23 @@
# Collections overview
The Collections package extends the concepts and collections in the core Unity engine, including adding more [native container objects](xref:JobSystemNativeContainer) and [job types](https://docs.unity3d.com/Manual/job-system-jobs.html). The collections in this package fall into the following categories:
* Collection types which have safety checks that make sure that Unity properly disposes of the type, and you use them in a thread-safe way. These types are in the [`Unity.Collections`](xref:Unity.Collections) namespace and their names start with `Native`.
* Collection types which don't have safety checks. These types are in the [`Unity.Collections.LowLevel.Unsafe`](xref:Unity.Collections.LowLevel.Unsafe) namespace and their names start with `Unsafe`.
The remaining collection types which don't fit into these categories aren't allocated and don't contain any pointers. These types only contain small amounts of data, and their disposal and thread safety aren't a concern.
## Native and unsafe comparison
`Native` collection types perform safety checks to make sure that indices passed to their methods are in bounds, but the other types don't have these kind of checks.
Several `Native` types have `Unsafe` equivalents, for example, [`NativeList`](xref:Unity.Collections.INativeList`1) has [`UnsafeList`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeList`1), and [`NativeHashMap`](xref:Unity.Collections.NativeHashMap`2) has [`UnsafeHashMap`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeHashMap`2).
It's best practice to use `Native` collections over the `Unsafe` equivalents. However, it's sometimes necessary to use the `Unsafe` equivalents because `Native` collection types can't contain other `Native` collections. This is because of how Unity implements the `Native` safety checks. For example, if you want to get a list of lists, you can use either `NativeList<UnsafeList<T>>` or `UnsafeList<UnsafeList<T>>`, but you can't use `NativeList<NativeList<T>>`.
If you've disabled safety checks, then there isn't a significant performance difference between a `Native` type and its `Unsafe` equivalent. In fact, most `Native` collections are implemented as wrappers of their `Unsafe` counterparts. For example, `NativeList` is made up of an `UnsafeList` plus some handles that the safety checks use.
## Additional resources
* [Collection types overview](collection-types.md)
* [Parallel readers and writers](parallel-readers.md)
@@ -0,0 +1,80 @@
apiRules:
- exclude:
# inherited Object methods
uidRegex: ^System\.Object\..*$
type: Method
- exclude:
# mentioning types from System.* namespace
uidRegex: ^System\..*$
type: Type
- exclude:
uidRegex: Tests$
type: Namespace
- exclude:
uidRegex: ^Unity\..*\.Tests\..*$
type: Namespace
- exclude:
uidRegex: .*Test.*
- exclude:
uidRegex: ^Unity\.Collections\.AllocatorManager\.BlockHandle
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.AllocatorManager\.AudioKernel
type: Member
- exclude:
uidRegex: ^Unity\.Collections\.AllocatorManager\.Initialize
type: Method
- exclude:
uidRegex: ^Unity\.Collections\.AllocatorManager\.Shutdown
type: Method
- exclude:
uidRegex: ^Unity\.Collections\.AllocatorManager\.AllocatorHandle\.Function
type: Property
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes126
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes16
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes30
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes4094
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes510
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.FixedBytes62
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.LowLevel\.Unsafe\.UntypedUnsafeParallelHashMap
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.SortJob\.SegmentSort
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.SortJob\.SegmentSort\.Execute
type: Method
- exclude:
uidRegex: ^Unity\.Collections\.SortJob\.SegmentSortMerge
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.SortJob\.SegmentSortMerge\.Execute
type: Method
- exclude:
uidRegex: ^Unity\.Collections\.SortJobDefer\.SegmentSort
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.SortJobDefer\.SegmentSort\.Execute
type: Method
- exclude:
uidRegex: ^Unity\.Collections\.SortJobDefer\.SegmentSortMerge
type: Type
- exclude:
uidRegex: ^Unity\.Collections\.SortJobDefer\.SegmentSortMerge\.Execute
type: Method
@@ -0,0 +1,16 @@
---
uid: collections-overview
---
# Collections package
The Collections package provides unmanaged data structures that you can use in [jobs](xref:JobSystem) and [Burst-compiled](https://docs.unity3d.com/Packages/com.unity.burst@latest) code.
|**Topic**|**Description**|
|---|---|
|[Collections overview](collections-overview.md)| Understand the collection types contained in this package.|
|[Use allocators to control unmanaged memory](allocation.md)| Understand how to use allocators to control unmanaged memory.|
## Additional resources
* [Job system documentation](xref:JobSystem)
* [Burst documentation](https://docs.unity3d.com/Packages/com.unity.burst@latest)
@@ -0,0 +1,32 @@
---
uid: collections-known-issues
---
# Known issues
All containers allocated with `Allocator.Temp` on the same thread use a shared `AtomicSafetyHandle` instance rather than each having their own. Most of the time, this isn't an issue because you can't pass `Temp` allocated collections into a job.
However, when you use `Native*HashMap`, `NativeParallelMultiHashMap`, `Native*HashSet`, and `NativeList` together with their secondary safety handle, this shared `AtomicSafetyHandle` instance is a problem.
A secondary safety handle ensures that a `NativeArray` which aliases a `NativeList` is invalidated when the `NativeList` is reallocated due to resizing.
Operations that invalidate an enumerator for these collection types, or invalidate the `NativeArray` that `NativeList.AsArray` returns also invalidates all other previously acquired enumerators. For example, the following throws an error when safety checks are enabled:
```c#
var list = new NativeList<int>(Allocator.Temp);
list.Add(1);
// This array uses the secondary safety handle of the list, which is
// shared between all Allocator.Temp allocations.
var array = list.AsArray();
var list2 = new NativeHashSet<int>(Allocator.Temp);
// This invalidates the secondary safety handle, which is also used
// by the list above.
list2.TryAdd(1);
// This throws an InvalidOperationException because the shared safety
// handle was invalidated.
var x = array[0];
```
@@ -0,0 +1,21 @@
# Parallel readers and writers
Several of the collection types have nested types to read and write from [parallel jobs](xref:JobSystemParallelForJobs). For example, to write safely to a `NativeList<T>` from a parallel job, you need to use [`NativeList<T>.ParallelWriter`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeList`1.ParallelWriter):
[!code-cs[parallel_writer](../DocCodeSamples.Tests/CollectionsExamples.cs#parallel_writer)]
[!code-cs[parallel_writer_job](../DocCodeSamples.Tests/CollectionsExamples.cs#parallel_writer_job)]
Note that these parallel readers and writers don't support the full functionality of the collection. For example, a `NativeList` can't grow its capacity in a parallel job because there's no way to safely allow this without incurring a synchronization overhead.
## Deterministic reading and writing
Although a `ParallelWriter` ensures the safety of concurrent writes, the order of the concurrent writes is indeterminstic because it depends on thread scheduling. The operating system and other factors outside of your program's control determine thread scheduling.
Likewise, although a `ParallelReader` ensures the safety of concurrent reads, the order of the concurrent reads is indeterminstic, you can't know which threads read which values.
To get around this, you can use either [`NativeStream`](xref:Unity.Collections.NativeStream) or [`UnsafeStream`](xref:Unity.Collections.LowLevel.Unsafe.UnsafeStream), which splits reads and writes into a separate buffer for each thread and avoids indeterminism.
Alternatively, you can effectively get a deterministic order of parallel reads if you deterministically divide the reads into separate ranges and process each range in its own thread.
You can also get a deterministic order if you deterministically sort the data after it has been written to the list.
@@ -0,0 +1,64 @@
# Performance Comparison: Allocators
> **<span style="color:red">This file is auto-generated</span>**
>
> All measurments were taken on 12th Gen Intel(R) Core(TM) i9-12900K with 24 logical cores.<br/>
> Unity Editor version: 2022.2.8f1<br/>
> To regenerate this file locally use: **DOTS -> Unity.Collections -> Generate &ast;&ast;&ast;** menu.<br/>
## Table of Contents
- [Benchmark Results](#benchmark-results)
- [RewindableAllocator](#rewindableallocator)
## Benchmark Results
The following benchmarks make **150 consecutive allocations** per sample set.<br/>Multithreaded benchmarks make the full **150 consecutive allocations *per worker thread*** per sample set.<br/>The **Min of 50 sample sets** is compared against the baseline on the far right side of the table.<br/>5 extra sample sets are run as warmup.<br/>
<br/>
> **Legend**
>
> `(S)` = Safety Enabled<br/>
> `(B)` = Burst Compiled *with Safety Disabled*<br/>
> `(S+B)` = Burst Compiled *with Safety Enabled*<br/>
> `(E)` = Engine Provided<br/>
> <br/>
> *`italic`* results are for benchmarking comparison only; these are not included in standard Performance Framework tests<br/>
<br/>
### *RewindableAllocator*
| Functionality | RewindableAllocator (S) | RewindableAllocator (S+B) | RewindableAllocator (B) | *TempJob (E)* | *Temp (E)* | *Persistent (E)* |
|---|--:|--:|--:|--:|--:|--:|
| `FixedSize(1, 1024)`*³* | 11.4µs  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.0µs   <span style="color:green">(6.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.8µs   <span style="color:green">(6.6x)</span>&nbsp;🟢 | *17.0µs  <span style="color:green">(1.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *10.1µs   <span style="color:green">(2.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *25.1µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(2, 1024)`*²˒³* | 23.0µs  <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 23.1µs   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 9.0µs   <span style="color:green">(5.2x)</span>&nbsp;🟢 | *20.2µs  <span style="color:green">(2.3x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.2µs   <span style="color:green">(4.2x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *47.2µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(4, 1024)`*²˒³* | 66.4µs  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 71.9µs   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 80.8µs   <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *23.5µs  <span style="color:green">(5.3x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.5µs  <span style="color:green">(10.7x)</span>*&nbsp;🟢 | *123.5µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(8, 1024)`*²˒³* | 167.1µs  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 169.2µs   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 167.3µs   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *45.6µs  <span style="color:green">(8.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *12.8µs  <span style="color:green">(28.6x)</span>*&nbsp;🟢 | *366.4µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(1, 1048576)`*³* | 11.9µs <span style="color:green">(16.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.7µs  <span style="color:green">(41.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.4µs  <span style="color:green">(44.1x)</span>&nbsp;🟢 | *17.1µs <span style="color:green">(11.4x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *10.9µs  <span style="color:green">(17.8x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *194.1µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(2, 1048576)`*²˒³* | 26.0µs <span style="color:green">(10.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.0µs  <span style="color:green">(15.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 14.1µs  <span style="color:green">(18.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *32.0µs  <span style="color:green">(8.1x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.7µs  <span style="color:green">(22.1x)</span>*&nbsp;🟢 | *258.9µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(4, 1048576)`*²˒³* | 70.1µs <span style="color:green">(11.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 71.3µs  <span style="color:green">(11.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 75.3µs  <span style="color:green">(10.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *208.5µs  <span style="color:green">(3.9x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *12.5µs  <span style="color:green">(65.0x)</span>*&nbsp;🟢 | *812.2µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `FixedSize(8, 1048576)`*²˒³* | 139.7µs <span style="color:green">(14.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 161.0µs  <span style="color:green">(12.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 179.8µs  <span style="color:green">(11.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1317.1µs  <span style="color:green">(1.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *19.5µs <span style="color:green">(104.6x)</span>*&nbsp;🟢 | *2039.9µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(1, 4096)`*⁴* | 11.9µs  <span style="color:green">(4.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.6µs  <span style="color:green">(10.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.3µs  <span style="color:green">(11.0x)</span>&nbsp;🟢 | *17.9µs  <span style="color:green">(2.6x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *10.3µs   <span style="color:green">(4.6x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *47.2µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(2, 4096)`*²˒⁴* | 26.8µs  <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.9µs  <span style="color:green">(11.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.5µs  <span style="color:green">(12.2x)</span>&nbsp;🟢 | *31.7µs  <span style="color:green">(4.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *10.9µs  <span style="color:green">(11.7x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *127.6µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(4, 4096)`*²˒⁴* | 58.9µs  <span style="color:green">(7.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 67.6µs   <span style="color:green">(6.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 64.5µs   <span style="color:green">(6.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *71.9µs  <span style="color:green">(6.2x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.2µs  <span style="color:green">(39.7x)</span>*&nbsp;🟢 | *444.7µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(8, 4096)`*²˒⁴* | 169.3µs  <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 159.0µs   <span style="color:green">(8.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 185.7µs   <span style="color:green">(7.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *350.8µs  <span style="color:green">(3.8x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.5µs <span style="color:green">(114.7x)</span>*&nbsp;🟢 | *1319.0µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(1, 65536)`*⁴* | 12.7µs <span style="color:green">(49.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 5.0µs <span style="color:green">(125.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.7µs <span style="color:green">(133.1x)</span>&nbsp;🟢 | *19.0µs <span style="color:green">(32.9x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.0µs  <span style="color:green">(56.9x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *625.4µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(2, 65536)`*²˒⁴* | 25.0µs <span style="color:green">(46.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.8µs  <span style="color:green">(73.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 13.0µs  <span style="color:green">(89.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *578.1µs  <span style="color:green">(2.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.3µs <span style="color:green">(102.5x)</span>*&nbsp;🟢 | *1157.7µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(4, 65536)`*²˒⁴* | 73.3µs <span style="color:green">(34.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 73.0µs  <span style="color:green">(34.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 70.5µs  <span style="color:green">(36.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2098.0µs  <span style="color:green">(1.2x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.9µs <span style="color:green">(213.6x)</span>*&nbsp;🟢 | *2542.2µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IncSize(8, 65536)`*²˒⁴* | 141.3µs <span style="color:green">(40.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 168.1µs  <span style="color:green">(34.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 162.6µs  <span style="color:green">(35.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *6036.0µs  <span style="color:red">(0.9x)</span>*&nbsp;🟠 | *12.7µs <span style="color:green">(450.8x)</span>*&nbsp;🟢 | *5724.9µs <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `DecSize(1, 4096)`*⁵* | 12.2µs  <span style="color:green">(6.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.6µs  <span style="color:green">(16.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.3µs  <span style="color:green">(17.2x)</span>&nbsp;🟢 | *16.9µs  <span style="color:green">(4.4x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *9.8µs   <span style="color:green">(7.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *73.9µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(2, 4096)`*²˒⁵* | 27.6µs  <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.5µs   <span style="color:green">(7.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.9µs   <span style="color:green">(8.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *37.3µs  <span style="color:green">(2.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.4µs   <span style="color:green">(8.3x)</span>*&nbsp;🟢 | *94.9µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(4, 4096)`*²˒⁵* | 68.5µs  <span style="color:green">(7.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 74.7µs   <span style="color:green">(6.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 69.4µs   <span style="color:green">(7.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *79.3µs  <span style="color:green">(6.5x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.0µs  <span style="color:green">(46.5x)</span>*&nbsp;🟢 | *511.6µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(8, 4096)`*²˒⁵* | 173.5µs  <span style="color:green">(7.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 173.4µs   <span style="color:green">(7.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 168.3µs   <span style="color:green">(7.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *313.4µs  <span style="color:green">(4.1x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *17.1µs  <span style="color:green">(75.1x)</span>*&nbsp;🟢 | *1284.6µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(1, 65536)`*⁵* | 12.1µs <span style="color:green">(47.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.6µs <span style="color:green">(126.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.3µs <span style="color:green">(134.8x)</span>&nbsp;🟢 | *20.8µs <span style="color:green">(27.9x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *11.7µs  <span style="color:green">(49.6x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *579.8µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(2, 65536)`*²˒⁵* | 28.6µs <span style="color:green">(37.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.7µs  <span style="color:green">(60.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.5µs  <span style="color:green">(92.3x)</span>&nbsp;🟢 | *658.8µs  <span style="color:green">(1.6x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *12.5µs  <span style="color:green">(84.9x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1061.4µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(4, 65536)`*²˒⁵* | 67.3µs <span style="color:green">(38.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 69.4µs  <span style="color:green">(37.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 73.1µs  <span style="color:green">(35.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2386.4µs  <span style="color:green">(1.1x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *14.2µs <span style="color:green">(183.8x)</span>*&nbsp;🟢 | *2609.3µs <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `DecSize(8, 65536)`*²˒⁵* | 154.4µs <span style="color:green">(37.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 166.6µs  <span style="color:green">(35.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 155.9µs  <span style="color:green">(37.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *5938.8µs  <span style="color:grey">(1.0x)</span>*&nbsp;🟠 | *28.6µs <span style="color:green">(203.9x)</span>*&nbsp;🟢 | *5830.8µs <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
*²* Benchmark run on parallel job workers - results may vary<br/>
*³* FixedSize(workerThreads, allocSize)<br/>
*⁴* IncSize(workerThreads, allocSize) -- Makes linearly increasing allocations [1⋅allocSize, 2⋅allocSize ... N⋅allocSize]<br/>
*⁵* DecSize(workerThreads, allocSize) -- Makes linearly decreasing allocations [N⋅allocSize ... 2⋅allocSize, 1⋅allocSize]<br/>
---
@@ -0,0 +1,378 @@
# Performance Comparison: Containers
> **<span style="color:red">This file is auto-generated</span>**
>
> All measurments were taken on Intel(R) Core(TM) i9-9900KS CPU @ 4.00GHz with 16 logical cores.<br/>
> Unity Editor version: 2022.3.6f1<br/>
> To regenerate this file locally use: **DOTS -> Unity.Collections -> Generate &ast;&ast;&ast;** menu.<br/>
## Table of Contents
- [Benchmark Results](#benchmark-results)
- [HashMap](#hashmap)
- [HashSet](#hashset)
- [List](#list)
- [ParallelHashMap](#parallelhashmap)
- [ParallelHashSet](#parallelhashset)
- [QueueParallelWriter](#queueparallelwriter)
- [Queue](#queue)
- [RingQueue](#ringqueue)
## Benchmark Results
The **Median of 10 sample sets** is compared against the baseline on the far right side of the table.<br/>Multithreaded benchmarks divide the processing amongst the specified number of workers.<br/>5 extra sample sets are run as warmup.<br/>
<br/>
> **Legend**
>
> `(S)` = Safety Enabled<br/>
> `(B)` = Burst Compiled *with Safety Disabled*<br/>
> `(S+B)` = Burst Compiled *with Safety Enabled*<br/>
> `(BCL)` = Base Class Library implementation (such as provided by Mono or .NET)<br/>
> <br/>
> *`italic`* results are for benchmarking comparison only; these are not included in standard Performance Framework tests<br/>
<br/>
### *HashMap*
| Functionality | NativeHashMap (S) | NativeHashMap (S+B) | NativeHashMap (B) | UnsafeHashMap (S) | UnsafeHashMap (S+B) | UnsafeHashMap (B) | *Dictionary (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(0)`*¹* | 0.342ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.133ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.221ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.105ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.106ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IsEmpty_x_100k(100)`*¹* | 0.342ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.112ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.133ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.221ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(0)`*¹* | 0.261ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.142ms <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.120ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(100)`*¹* | 0.261ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.142ms <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.120ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArrayKeys(10000)` | 0.151ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.126ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.092ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.159ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 0.125ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.083ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.018ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `ToNativeArrayKeys(100000)` | 1.659ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 1.214ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.918ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.610ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.205ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.908ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.174ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `ToNativeArrayKeys(1000000)` | 21.689ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 13.624ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.721ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.842ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 13.505ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.569ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.059ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `ToNativeArrayValues(10000)` | 0.160ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.118ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.086ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 0.125ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.018ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `ToNativeArrayValues(100000)` | 1.702ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.192ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.935ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.721ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 1.196ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.919ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.173ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `ToNativeArrayValues(1000000)` | 20.402ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 13.609ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.017ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 20.556ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 13.773ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.869ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.018ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Insert(10000)` | 0.135ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.070ms <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.061ms <span style="color:green">(2.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.120ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.060ms <span style="color:green">(2.9x)</span>&nbsp;🟢 | 0.061ms <span style="color:green">(2.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.175ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(100000)` | 1.723ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.996ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.914ms <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.565ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.909ms <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.889ms <span style="color:green">(2.5x)</span>&nbsp;🟢 | *2.209ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1000000)` | 33.017ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 21.056ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.847ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 50.228ms <span style="color:red">(0.6x)</span>&nbsp;🟠 | 19.654ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.613ms <span style="color:green">(1.5x)</span>&nbsp;🟢 | *29.738ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `AddGrow(4, 1048576)`*³* | 137.459ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 81.364ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 77.039ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 133.603ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 78.458ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 76.533ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *49.222ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `AddGrow(65536, 1048576)`*³* | 140.883ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 82.611ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 77.670ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 134.717ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 79.913ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 77.316ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *50.215ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Contains(10000)` | 0.089ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.027ms <span style="color:green">(6.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.101ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.029ms <span style="color:green">(6.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.025ms <span style="color:green">(7.4x)</span>&nbsp;🟢 | *0.188ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(100000)` | 1.696ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.694ms <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.508ms <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.945ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.538ms <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.482ms <span style="color:green">(5.9x)</span>&nbsp;🟢 | *2.843ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1000000)` | 42.805ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.135ms <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.633ms <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 43.284ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.700ms <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.703ms <span style="color:green">(5.3x)</span>&nbsp;🟢 | *62.072ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(10000)` | 0.109ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.028ms <span style="color:green">(6.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.032ms <span style="color:green">(5.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.122ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.027ms <span style="color:green">(7.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.026ms <span style="color:green">(7.1x)</span>&nbsp;🟢 | *0.189ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(100000)` | 1.983ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.592ms <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.614ms <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.125ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.543ms <span style="color:green">(5.1x)</span>&nbsp;🟢 | 0.545ms <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.791ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(1000000)` | 57.739ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.881ms <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.937ms <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 57.860ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 14.918ms <span style="color:green">(4.1x)</span>&nbsp;🟢 | 15.113ms <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *61.850ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(10000)` | 0.103ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.080ms <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.040ms <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.039ms <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms <span style="color:green">(5.8x)</span>&nbsp;🟢 | *0.209ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(100000)` | 1.890ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.269ms <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.755ms <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.473ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.759ms <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.707ms <span style="color:green">(4.3x)</span>&nbsp;🟢 | *3.074ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(1000000)` | 73.370ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 69.054ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 65.695ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 73.500ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 65.870ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 66.574ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *73.729ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(10000)` | 0.105ms <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.033ms <span style="color:green">(5.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.032ms <span style="color:green">(5.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.120ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.029ms <span style="color:green">(6.6x)</span>&nbsp;🟢 | 0.029ms <span style="color:green">(6.6x)</span>&nbsp;🟢 | *0.191ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(100000)` | 1.943ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.645ms <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.637ms <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.102ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.574ms <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.557ms <span style="color:green">(5.1x)</span>&nbsp;🟢 | *2.816ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(1000000)` | 55.056ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.084ms <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.878ms <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 59.138ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.889ms <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.692ms <span style="color:green">(4.0x)</span>&nbsp;🟢 | *62.067ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(10000)` | 0.110ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.044ms <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.035ms <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.094ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.029ms <span style="color:green">(5.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.028ms <span style="color:green">(5.6x)</span>&nbsp;🟢 | *0.158ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(100000)` | 1.889ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.844ms <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.661ms <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.654ms <span style="color:red">(0.7x)</span>&nbsp;🟠 | 0.566ms <span style="color:green">(4.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.547ms <span style="color:green">(4.4x)</span>&nbsp;🟢 | *2.395ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Remove(1000000)` | 62.623ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 56.372ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 53.877ms <span style="color:green">(1.2x)</span>&nbsp;🟢 | 61.104ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 54.841ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 55.805ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *62.915ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(10000)` | 0.150ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.083ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.077ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.141ms <span style="color:red">(0.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.077ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.079ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.041ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Foreach(100000)` | 1.984ms <span style="color:red">(0.2x)</span>&nbsp;🟠 | 0.924ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.866ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.869ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.865ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.885ms <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.412ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Foreach(1000000)` | 27.605ms <span style="color:red">(0.2x)</span>&nbsp;🟠 | 10.947ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.421ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 26.351ms <span style="color:red">(0.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.457ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.619ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *4.359ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
*¹* Optimizations were disabled to perform this benchmark<br/>
*³* AddGrow(capacity, growTo) -- Incrementally grows from `capacity` until reaching size of `growTo`<br/>
---
<br/>
### *HashSet*
| Functionality | NativeHashSet (S) | NativeHashSet (S+B) | NativeHashSet (B) | UnsafeHashSet (S) | UnsafeHashSet (S+B) | UnsafeHashSet (B) | *HashSet (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(0)`*¹* | 0.342ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.112ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.133ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.221ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms <span style="color:green">(1.3x)</span>&nbsp;🟢 | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IsEmpty_x_100k(100)`*¹* | 0.342ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.112ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.133ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.221ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;🟢 | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(0)`*¹* | 0.261ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.143ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.100ms <span style="color:green">(1.4x)</span>&nbsp;🟢 | 0.111ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(100)`*¹* | 0.261ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.142ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.100ms <span style="color:green">(1.4x)</span>&nbsp;🟢 | 0.111ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(10000)` | 0.043ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.015ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.043ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.015ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms  <span style="color:green">(1.9x)</span>&nbsp;🟢 | *0.018ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(100000)` | 0.475ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.144ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.085ms  <span style="color:green">(2.1x)</span>&nbsp;🟢 | 0.485ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.144ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.085ms  <span style="color:green">(2.1x)</span>&nbsp;🟢 | *0.176ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(1000000)` | 4.935ms <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.591ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.989ms  <span style="color:green">(1.9x)</span>&nbsp;🟢 | 5.378ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 1.586ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.997ms  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.927ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Insert(10000)` | 0.093ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.044ms <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.040ms  <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.078ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.039ms <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.035ms  <span style="color:green">(2.9x)</span>&nbsp;🟢 | *0.103ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(100000)` | 0.937ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.441ms <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.403ms  <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.785ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.390ms <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.351ms  <span style="color:green">(2.9x)</span>&nbsp;🟢 | *1.029ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1000000)` | 12.275ms <span style="color:red">(0.8x)</span>&nbsp;🟠 | 7.030ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.650ms  <span style="color:green">(1.6x)</span>&nbsp;🟢 | 10.495ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.902ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.747ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *10.384ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `AddGrow(4, 1048576)`*³* | 76.515ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 35.430ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 33.171ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 75.704ms <span style="color:red">(0.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 32.776ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 30.928ms  <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *20.387ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `AddGrow(65536, 1048576)`*³* | 75.192ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 34.149ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 32.652ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 74.248ms <span style="color:red">(0.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 34.092ms <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 32.440ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *19.978ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Contains(10000)` | 0.061ms <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:green">(6.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.010ms <span style="color:green">(11.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.072ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.013ms <span style="color:green">(8.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms <span style="color:green">(12.5x)</span>&nbsp;🟢 | *0.113ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(100000)` | 0.949ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.311ms <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.199ms  <span style="color:green">(8.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.104ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.207ms <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.180ms  <span style="color:green">(8.9x)</span>&nbsp;🟢 | *1.610ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1000000)` | 11.436ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.877ms <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.576ms  <span style="color:green">(7.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 13.252ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.653ms <span style="color:green">(7.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.373ms  <span style="color:green">(8.0x)</span>&nbsp;🟢 | *19.089ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(10000)` | 0.111ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.054ms <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.044ms  <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.101ms <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms <span style="color:green">(5.2x)</span>&nbsp;🟢 | 0.040ms  <span style="color:green">(4.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.186ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(100000)` | 1.327ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.645ms <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.531ms  <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.218ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.438ms <span style="color:green">(4.7x)</span>&nbsp;🟢 | 0.477ms  <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.076ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1000000)` | 15.132ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.264ms <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 5.953ms  <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 26.197ms <span style="color:red">(0.9x)</span>&nbsp;🟠 | 4.917ms <span style="color:green">(4.7x)</span>&nbsp;🟢 | 5.268ms  <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *23.150ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(10000)` | 0.081ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.029ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.016ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | 0.054ms <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.036ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(100000)` | 0.766ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.241ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.135ms  <span style="color:green">(2.6x)</span>&nbsp;🟢 | 0.505ms <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.145ms <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.145ms  <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.356ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(1000000)` | 7.540ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 2.280ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.431ms  <span style="color:green">(2.5x)</span>&nbsp;🟢 | 4.906ms <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.524ms <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.516ms  <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.638ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `UnionWith(10000)` | 0.226ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.144ms <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.128ms  <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.191ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.119ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.116ms  <span style="color:green">(2.2x)</span>&nbsp;🟢 | *0.254ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `UnionWith(100000)` | 2.545ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.664ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.486ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.140ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.370ms <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.349ms  <span style="color:green">(2.6x)</span>&nbsp;🟢 | *3.441ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `UnionWith(1000000)` | 80.802ms <span style="color:red">(0.7x)</span>&nbsp;🟠 | 43.823ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.187ms  <span style="color:green">(1.5x)</span>&nbsp;🟢 | 74.811ms <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 45.527ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 40.115ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *59.785ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IntersectWith(10000)` | 0.246ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.142ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.123ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.201ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.107ms <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.105ms  <span style="color:green">(2.6x)</span>&nbsp;🟢 | *0.270ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IntersectWith(100000)` | 2.705ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.546ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.405ms  <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.218ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.189ms <span style="color:green">(2.9x)</span>&nbsp;🟢 | 1.231ms  <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.436ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IntersectWith(1000000)` | 33.228ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.026ms <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.066ms  <span style="color:green">(3.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 27.030ms <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 14.937ms <span style="color:green">(4.4x)</span>&nbsp;🟢 | 15.096ms  <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *65.055ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ExceptWith(10000)` | 0.212ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.125ms <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.107ms  <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.175ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.094ms <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.093ms  <span style="color:green">(2.4x)</span>&nbsp;🟢 | *0.218ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ExceptWith(100000)` | 2.374ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.419ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.257ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.992ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.109ms <span style="color:green">(2.5x)</span>&nbsp;🟢 | 1.110ms  <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.799ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ExceptWith(1000000)` | 35.627ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.482ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.001ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 29.688ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.493ms <span style="color:green">(2.6x)</span>&nbsp;🟢 | 15.620ms  <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *39.627ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*¹* Optimizations were disabled to perform this benchmark<br/>
*³* AddGrow(capacity, growTo) -- Incrementally grows from `capacity` until reaching size of `growTo`<br/>
---
<br/>
### *List*
| Functionality | NativeList (S) | NativeList (S+B) | NativeList (B) | UnsafeList (S) | UnsafeList (S+B) | UnsafeList (B) | *List (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(0)`*¹* | 0.154ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.121ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;🟢 | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;🟢 | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IsEmpty_x_100k(100)`*¹* | 0.154ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.121ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.106ms  <span style="color:green">(1.3x)</span>&nbsp;🟢 | *0.140ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(0)`*¹* | 0.120ms <span style="color:grey">(1.0x)</span>&nbsp;🟠 | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.020ms <span style="color:green">(6.0x)</span>&nbsp;🟢 | 0.081ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(100)`*¹* | 0.120ms <span style="color:grey">(1.0x)</span>&nbsp;🟠 | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.020ms <span style="color:green">(6.0x)</span>&nbsp;🟢 | 0.081ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms  <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArray(10000)` | 0.002ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms  <span style="color:green">(1.9x)</span>&nbsp;🟢 | --- | --- | --- | *0.003ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArray(100000)` | 0.088ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.015ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.015ms  <span style="color:green">(2.0x)</span>&nbsp;🟢 | --- | --- | --- | *0.029ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(1000000)` | 0.906ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.143ms <span style="color:green">(2.1x)</span>&nbsp;🟢 | 0.148ms  <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *0.306ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Add(10000)` | 0.040ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.014ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.016ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.007ms  <span style="color:green">(2.2x)</span>&nbsp;🟢 | 0.007ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.014ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Add(100000)` | 0.400ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.140ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.155ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.166ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.061ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | 0.061ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | *0.144ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Add(1000000)` | 4.000ms <span style="color:red">(0.4x)</span>&nbsp;🟠 | 1.399ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.548ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.654ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.605ms  <span style="color:green">(2.4x)</span>&nbsp;🟢 | 0.608ms  <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.436ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `AddGrow(4, 1048576)`*³* | 4.647ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 1.886ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.759ms  <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.141ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.026ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | 1.033ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.402ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `AddGrow(65536, 1048576)`*³* | 4.604ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 1.865ms <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.773ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.122ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.083ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.010ms  <span style="color:green">(2.4x)</span>&nbsp;🟢 | *2.381ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Contains(1000)` | 0.371ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.086ms <span style="color:green">(4.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms  <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.370ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.148ms  <span style="color:green">(2.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms  <span style="color:green">(4.7x)</span>&nbsp;🟢 | *0.394ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(10000)` | 37.241ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.565ms <span style="color:green">(6.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.548ms  <span style="color:green">(6.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 37.203ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.541ms  <span style="color:green">(6.0x)</span>&nbsp;🟢 | 7.544ms  <span style="color:green">(6.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *45.509ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(10000)` | 0.037ms <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.009ms <span style="color:green">(2.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.005ms  <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.022ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.005ms  <span style="color:green">(5.0x)</span>&nbsp;🟢 | 0.005ms  <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.023ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IndexedRead(100000)` | 0.474ms <span style="color:red">(0.7x)</span>&nbsp;🟠 | 0.090ms <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.068ms  <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.268ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.077ms  <span style="color:green">(4.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.068ms  <span style="color:green">(4.8x)</span>&nbsp;🟢 | *0.328ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IndexedRead(1000000)` | 5.416ms <span style="color:red">(0.7x)</span>&nbsp;🟠 | 1.487ms <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.341ms  <span style="color:green">(2.9x)</span>&nbsp;🟢 | 3.197ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.395ms  <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.357ms  <span style="color:green">(2.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.897ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IndexedWrite(10000)` | 0.028ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.011ms <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.007ms  <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.006ms  <span style="color:green">(4.6x)</span>&nbsp;🟢 | 0.010ms  <span style="color:green">(3.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.029ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(100000)` | 0.311ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.125ms <span style="color:green">(2.7x)</span>&nbsp;🟢 | 0.135ms  <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.220ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.136ms  <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.132ms  <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.331ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(1000000)` | 3.656ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.892ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.868ms  <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.775ms <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.796ms  <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.744ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | *3.956ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1000)` | 0.087ms <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.011ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.011ms  <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.085ms <span style="color:red">(0.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.011ms  <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.010ms  <span style="color:green">(2.2x)</span>&nbsp;🟢 | *0.022ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Remove(10000)` | 7.626ms <span style="color:red">(0.1x)</span>&nbsp;🟠 | 0.732ms <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.717ms  <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.616ms <span style="color:red">(0.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.716ms  <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.704ms  <span style="color:green">(1.2x)</span>&nbsp;🟢 | *0.853ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(10000)` | 0.038ms <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.004ms <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.003ms  <span style="color:green">(8.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.016ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.003ms  <span style="color:green">(9.0x)</span>&nbsp;🟢 | 0.003ms  <span style="color:green">(9.0x)</span>&nbsp;🟢 | *0.024ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(100000)` | 0.381ms <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.037ms <span style="color:green">(6.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.024ms <span style="color:green">(10.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.160ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.024ms <span style="color:green">(10.0x)</span>&nbsp;🟢 | 0.024ms <span style="color:green">(10.0x)</span>&nbsp;🟢 | *0.242ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(1000000)` | 3.815ms <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.360ms <span style="color:green">(6.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.229ms <span style="color:green">(10.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.621ms <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.226ms <span style="color:green">(10.7x)</span>&nbsp;🟢 | 0.226ms <span style="color:green">(10.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.419ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
*¹* Optimizations were disabled to perform this benchmark<br/>
*³* AddGrow(capacity, growTo) -- Incrementally grows from `capacity` until reaching size of `growTo`<br/>
---
<br/>
### *ParallelHashMap*
| Functionality | NativeParallelHashMap (S) | NativeParallelHashMap (S+B) | NativeParallelHashMap (B) | UnsafeParallelHashMap (S) | UnsafeParallelHashMap (S+B) | UnsafeParallelHashMap (B) | *ConcurrentDictionary (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(1, 0)`*¹* | 0.462ms  <span style="color:green">(176.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.141ms  <span style="color:green">(577.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.109ms  <span style="color:green">(748.4x)</span>&nbsp;🟢 | 0.261ms  <span style="color:green">(312.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.162ms  <span style="color:green">(501.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.174ms  <span style="color:green">(469.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *81.423ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(2, 0)`*¹˒²* | 0.234ms  <span style="color:green">(551.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.072ms <span style="color:green">(1782.5x)</span>&nbsp;🟢 | 0.090ms <span style="color:green">(1427.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.134ms  <span style="color:green">(965.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.096ms <span style="color:green">(1338.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.091ms <span style="color:green">(1412.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *129.140ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(4, 0)`*¹˒²* | 0.267ms  <span style="color:green">(644.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.042ms <span style="color:green">(4088.3x)</span>&nbsp;🟢 | 0.050ms <span style="color:green">(3473.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.078ms <span style="color:green">(2214.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.048ms <span style="color:green">(3604.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.047ms <span style="color:green">(3626.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *171.914ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(1, 100)`*¹* | 0.682ms  <span style="color:green">(114.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.238ms  <span style="color:green">(326.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.242ms  <span style="color:green">(322.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.582ms  <span style="color:green">(133.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.181ms  <span style="color:green">(429.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.181ms  <span style="color:green">(429.9x)</span>&nbsp;🟢 | *77.786ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(2, 100)`*¹˒²* | 0.380ms  <span style="color:green">(341.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.124ms <span style="color:green">(1046.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.142ms  <span style="color:green">(911.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.295ms  <span style="color:green">(440.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.093ms <span style="color:green">(1399.5x)</span>&nbsp;🟢 | 0.095ms <span style="color:green">(1370.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *129.804ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(4, 100)`*¹˒²* | 0.354ms  <span style="color:green">(490.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.114ms <span style="color:green">(1518.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.125ms <span style="color:green">(1385.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.217ms  <span style="color:green">(799.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.109ms <span style="color:green">(1596.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.062ms <span style="color:green">(2818.0x)</span>&nbsp;🟢 | *173.587ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(1, 0)`*¹* | 0.535ms  <span style="color:green">(150.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.201ms  <span style="color:green">(401.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.155ms  <span style="color:green">(521.9x)</span>&nbsp;🟢 | 0.287ms  <span style="color:green">(280.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.181ms  <span style="color:green">(445.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms  <span style="color:green">(501.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *80.634ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(2, 0)`*¹˒²* | 0.271ms  <span style="color:green">(455.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.103ms <span style="color:green">(1195.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.080ms <span style="color:green">(1532.7x)</span>&nbsp;🟢 | 0.148ms  <span style="color:green">(831.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.093ms <span style="color:green">(1326.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.083ms <span style="color:green">(1491.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *123.229ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(4, 0)`*¹˒²* | 0.144ms <span style="color:green">(1320.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.061ms <span style="color:green">(3106.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.046ms <span style="color:green">(4132.8x)</span>&nbsp;🟢 | 0.083ms <span style="color:green">(2294.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.103ms <span style="color:green">(1846.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.051ms <span style="color:green">(3730.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *189.491ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(1, 100)`*¹* | 3.685ms   <span style="color:green">(25.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.444ms   <span style="color:green">(65.7x)</span>&nbsp;🟢 | 1.693ms   <span style="color:green">(56.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.191ms   <span style="color:green">(29.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.544ms   <span style="color:green">(61.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.614ms   <span style="color:green">(58.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *94.884ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(2, 100)`*¹˒²* | 1.845ms   <span style="color:green">(73.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.736ms  <span style="color:green">(185.3x)</span>&nbsp;🟢 | 0.887ms  <span style="color:green">(153.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.595ms   <span style="color:green">(85.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.773ms  <span style="color:green">(176.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.825ms  <span style="color:green">(165.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *136.423ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(4, 100)`*¹˒²* | 1.613ms  <span style="color:green">(113.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.708ms  <span style="color:green">(259.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.707ms  <span style="color:green">(259.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.460ms  <span style="color:green">(125.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.746ms  <span style="color:green">(246.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.689ms  <span style="color:green">(266.5x)</span>&nbsp;🟢 | *183.655ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArrayKeys(1, 10000)` | 0.150ms    <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.121ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.081ms    <span style="color:green">(2.2x)</span>&nbsp;🟢 | 0.201ms    <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.129ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.180ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArrayKeys(1, 100000)` | 1.652ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.243ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.052ms    <span style="color:green">(2.2x)</span>&nbsp;🟢 | 1.796ms    <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.402ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.053ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.336ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArrayKeys(1, 1000000)` | 36.653ms    <span style="color:red">(0.7x)</span>&nbsp;🟠 | 17.665ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.848ms    <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.236ms    <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.985ms    <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.798ms    <span style="color:green">(2.3x)</span>&nbsp;🟢 | *25.361ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArrayValues(1, 10000)` | 0.150ms    <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.121ms    <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.080ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.151ms    <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.122ms    <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.079ms    <span style="color:green">(1.8x)</span>&nbsp;🟢 | *0.141ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArrayValues(1, 100000)` | 1.626ms    <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.235ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.862ms    <span style="color:green">(2.1x)</span>&nbsp;🟢 | 1.629ms    <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.229ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.872ms    <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.773ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArrayValues(1, 1000000)` | 20.867ms    <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.371ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.046ms    <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 24.782ms    <span style="color:grey">(1.0x)</span>&nbsp;🟠 | 17.345ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.785ms    <span style="color:green">(2.2x)</span>&nbsp;🟢 | *23.593ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Insert(1, 10000)` | 0.353ms    <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.209ms    <span style="color:green">(9.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.212ms    <span style="color:green">(9.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.320ms    <span style="color:green">(6.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.205ms    <span style="color:green">(9.6x)</span>&nbsp;🟢 | 0.211ms    <span style="color:green">(9.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.979ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 10000)`*²* | 0.543ms    <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.514ms    <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.329ms    <span style="color:green">(7.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.400ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.266ms    <span style="color:green">(8.8x)</span>&nbsp;🟢 | 0.379ms    <span style="color:green">(6.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.330ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 10000)`*²* | 0.449ms    <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.290ms    <span style="color:green">(8.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.217ms   <span style="color:green">(10.6x)</span>&nbsp;🟢 | 0.285ms    <span style="color:green">(8.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.249ms    <span style="color:green">(9.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.270ms    <span style="color:green">(8.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.314ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1, 100000)` | 3.818ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.325ms    <span style="color:green">(9.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.281ms    <span style="color:green">(9.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.442ms    <span style="color:green">(6.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.218ms    <span style="color:green">(9.9x)</span>&nbsp;🟢 | 2.285ms    <span style="color:green">(9.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *21.983ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 100000)`*²* | 5.611ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.873ms    <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.254ms    <span style="color:green">(7.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.090ms    <span style="color:green">(5.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.645ms    <span style="color:green">(8.8x)</span>&nbsp;🟢 | 3.080ms    <span style="color:green">(7.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *23.181ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 100000)`*²* | 4.523ms    <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.897ms    <span style="color:green">(8.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.156ms   <span style="color:green">(11.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.541ms    <span style="color:green">(6.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.201ms   <span style="color:green">(11.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.096ms   <span style="color:green">(11.5x)</span>&nbsp;🟢 | *24.121ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1, 1000000)` | 60.383ms    <span style="color:green">(7.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.007ms   <span style="color:green">(11.8x)</span>&nbsp;🟢 | 36.109ms   <span style="color:green">(11.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 53.923ms    <span style="color:green">(7.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.016ms   <span style="color:green">(11.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.542ms   <span style="color:green">(11.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *425.024ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 1000000)`*²* | 62.895ms    <span style="color:green">(7.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 50.118ms    <span style="color:green">(8.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 40.151ms   <span style="color:green">(11.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 50.271ms    <span style="color:green">(8.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.964ms   <span style="color:green">(11.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 38.384ms   <span style="color:green">(11.6x)</span>&nbsp;🟢 | *443.920ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 1000000)`*²* | 42.694ms    <span style="color:green">(7.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.240ms    <span style="color:green">(9.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 24.896ms   <span style="color:green">(13.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 30.771ms   <span style="color:green">(10.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 24.408ms   <span style="color:green">(13.3x)</span>&nbsp;🟢 | 25.097ms   <span style="color:green">(13.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *325.595ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `AddGrow(1, 4, 1048576)`*³* | 72.547ms    <span style="color:green">(5.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.816ms   <span style="color:green">(10.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.313ms   <span style="color:green">(10.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 71.458ms    <span style="color:green">(6.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.813ms   <span style="color:green">(10.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.265ms   <span style="color:green">(10.8x)</span>&nbsp;🟢 | *425.495ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `AddGrow(1, 65536, 1048576)`*³* | 68.046ms   <span style="color:green">(10.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 39.004ms   <span style="color:green">(17.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 38.764ms   <span style="color:green">(17.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 67.198ms   <span style="color:green">(10.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 38.417ms   <span style="color:green">(17.8x)</span>&nbsp;🟢 | 38.540ms   <span style="color:green">(17.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *683.780ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 10000)` | 0.145ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.033ms    <span style="color:green">(6.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.028ms    <span style="color:green">(8.0x)</span>&nbsp;🟢 | 0.118ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms    <span style="color:green">(6.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.029ms    <span style="color:green">(7.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.228ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 10000)`*²* | 0.127ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.042ms    <span style="color:green">(4.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms    <span style="color:green">(5.4x)</span>&nbsp;🟢 | 0.111ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.038ms    <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms    <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.194ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 10000)`*²* | 0.167ms    <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.052ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.055ms    <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.100ms    <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.068ms    <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.039ms    <span style="color:green">(5.5x)</span>&nbsp;🟢 | *0.213ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 100000)` | 2.247ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.650ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.498ms    <span style="color:green">(6.6x)</span>&nbsp;🟢 | 1.849ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.650ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.500ms    <span style="color:green">(6.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.277ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 100000)`*²* | 1.226ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.403ms    <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.328ms    <span style="color:green">(5.4x)</span>&nbsp;🟢 | 1.077ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.408ms    <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.330ms    <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.761ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 100000)`*²* | 1.065ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.334ms    <span style="color:green">(7.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.268ms    <span style="color:green">(8.7x)</span>&nbsp;🟢 | 0.883ms    <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.319ms    <span style="color:green">(7.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.540ms    <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.332ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 1000000)` | 66.122ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.585ms    <span style="color:green">(5.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.089ms    <span style="color:green">(8.0x)</span>&nbsp;🟢 | 59.523ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.021ms    <span style="color:green">(5.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.118ms    <span style="color:green">(8.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *97.095ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 1000000)`*²* | 31.624ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 8.707ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.498ms    <span style="color:green">(7.8x)</span>&nbsp;🟢 | 29.568ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 8.714ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.511ms    <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *50.806ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 1000000)`*²* | 25.406ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.925ms    <span style="color:green">(6.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 5.677ms    <span style="color:green">(7.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 22.636ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 6.716ms    <span style="color:green">(6.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 5.494ms    <span style="color:green">(7.9x)</span>&nbsp;🟢 | *43.614ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(1, 10000)` | 0.145ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.029ms    <span style="color:green">(8.1x)</span>&nbsp;🟢 | 0.032ms    <span style="color:green">(7.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.137ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.031ms    <span style="color:green">(7.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.031ms    <span style="color:green">(7.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.235ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(2, 10000)`*²* | 0.202ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.059ms    <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.062ms    <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.191ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.041ms    <span style="color:green">(7.0x)</span>&nbsp;🟢 | 0.066ms    <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.288ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(4, 10000)`*²* | 0.581ms    <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.129ms    <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.098ms    <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.264ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.071ms    <span style="color:green">(7.1x)</span>&nbsp;🟢 | 0.097ms    <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.501ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IndexedRead(1, 100000)` | 2.216ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.592ms    <span style="color:green">(5.6x)</span>&nbsp;🟢 | 0.604ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.140ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.600ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.607ms    <span style="color:green">(5.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.291ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(2, 100000)`*²* | 2.416ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.698ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.692ms    <span style="color:green">(5.1x)</span>&nbsp;🟢 | 2.270ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.707ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.743ms    <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.506ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(4, 100000)`*²* | 4.094ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.071ms    <span style="color:green">(5.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.053ms    <span style="color:green">(5.5x)</span>&nbsp;🟢 | 7.214ms    <span style="color:red">(0.8x)</span>&nbsp;🟠 | 1.058ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.794ms    <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *5.780ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IndexedRead(1, 1000000)` | 64.603ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.636ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.726ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 62.234ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.652ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.411ms    <span style="color:green">(5.6x)</span>&nbsp;🟢 | *96.983ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(2, 1000000)`*²* | 63.460ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.217ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.124ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 61.578ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.127ms    <span style="color:green">(5.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.957ms    <span style="color:green">(5.8x)</span>&nbsp;🟢 | *99.146ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedRead(4, 1000000)`*²* | 68.243ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 28.318ms    <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 27.812ms    <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 69.192ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 26.990ms    <span style="color:green">(3.6x)</span>&nbsp;🟢 | 27.918ms    <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *97.383ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(1, 10000)` | 0.164ms    <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.051ms    <span style="color:green">(9.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.041ms   <span style="color:green">(11.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.131ms    <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.040ms   <span style="color:green">(11.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.038ms   <span style="color:green">(12.0x)</span>&nbsp;🟢 | *0.456ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(1, 100000)` | 2.333ms    <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.901ms    <span style="color:green">(6.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.731ms    <span style="color:green">(8.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.077ms    <span style="color:green">(2.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.781ms    <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.710ms    <span style="color:green">(8.5x)</span>&nbsp;🟢 | *6.067ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IndexedWrite(1, 1000000)` | 76.627ms    <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 67.296ms    <span style="color:green">(2.8x)</span>&nbsp;🟢 | 68.052ms    <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 85.977ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 68.516ms    <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 69.221ms    <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *191.108ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(1, 10000)` | 0.154ms    <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.043ms    <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.032ms    <span style="color:green">(6.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.117ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.043ms    <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.031ms    <span style="color:green">(6.6x)</span>&nbsp;🟢 | *0.206ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(2, 10000)`*²* | 0.125ms    <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.045ms    <span style="color:green">(3.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms    <span style="color:green">(4.8x)</span>&nbsp;🟢 | 0.110ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.046ms    <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.036ms    <span style="color:green">(4.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.172ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(4, 10000)`*²* | 0.170ms    <span style="color:red">(0.7x)</span>&nbsp;🟠 | 0.051ms    <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.038ms    <span style="color:green">(3.3x)</span>&nbsp;🟢 | 0.103ms    <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.078ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.039ms    <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.125ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `TryGetValue(1, 100000)` | 2.187ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.839ms    <span style="color:green">(4.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.616ms    <span style="color:green">(5.4x)</span>&nbsp;🟢 | 1.925ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.815ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.628ms    <span style="color:green">(5.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.336ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(2, 100000)`*²* | 1.216ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.478ms    <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.342ms    <span style="color:green">(5.2x)</span>&nbsp;🟢 | 1.072ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.489ms    <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.391ms    <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.769ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(4, 100000)`*²* | 1.042ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.408ms    <span style="color:green">(4.3x)</span>&nbsp;🟢 | 0.617ms    <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.899ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.915ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.636ms    <span style="color:green">(2.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.736ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(1, 1000000)` | 65.145ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 25.321ms    <span style="color:green">(3.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.163ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 59.895ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 23.602ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.464ms    <span style="color:green">(5.2x)</span>&nbsp;🟢 | *96.395ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(2, 1000000)`*²* | 31.724ms    <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.422ms    <span style="color:green">(4.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 9.631ms    <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 30.638ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.432ms    <span style="color:green">(4.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 9.589ms    <span style="color:green">(5.1x)</span>&nbsp;🟢 | *49.107ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `TryGetValue(4, 1000000)`*²* | 25.831ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.070ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.992ms    <span style="color:green">(5.2x)</span>&nbsp;🟢 | 23.710ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.235ms    <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 8.062ms    <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *41.691ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 10000)` | 0.120ms    <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.214ms    <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.050ms   <span style="color:green">(11.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.095ms    <span style="color:green">(5.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.050ms   <span style="color:green">(10.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.049ms   <span style="color:green">(11.1x)</span>&nbsp;🟢 | *0.545ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 100000)` | 1.928ms    <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.929ms    <span style="color:green">(7.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.805ms    <span style="color:green">(8.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.682ms    <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.867ms    <span style="color:green">(7.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.793ms    <span style="color:green">(8.2x)</span>&nbsp;🟢 | *6.512ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 1000000)` | 64.353ms    <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 56.893ms    <span style="color:green">(3.5x)</span>&nbsp;🟢 | 57.422ms    <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 62.480ms    <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 57.884ms    <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 57.271ms    <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *196.582ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(1, 10000)` | 0.156ms    <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.086ms    <span style="color:green">(4.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.073ms    <span style="color:green">(5.4x)</span>&nbsp;🟢 | 0.143ms    <span style="color:green">(2.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.080ms    <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.080ms    <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.393ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(1, 100000)` | 2.094ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.931ms    <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.839ms    <span style="color:green">(5.8x)</span>&nbsp;🟢 | 1.862ms    <span style="color:green">(2.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.885ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.884ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *4.876ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(1, 1000000)` | 28.544ms    <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.060ms    <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.143ms    <span style="color:green">(5.6x)</span>&nbsp;🟢 | 27.167ms    <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.318ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 10.364ms    <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *56.852ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*¹* Optimizations were disabled to perform this benchmark<br/>
*²* Benchmark run on parallel job workers - results may vary<br/>
*³* AddGrow(workers, capacity, growTo) -- Incrementally grows from `capacity` until reaching size of `growTo`<br/>
---
<br/>
### *ParallelHashSet*
| Functionality | NativeParallelHashSet (S) | NativeParallelHashSet (S+B) | NativeParallelHashSet (B) | UnsafeParallelHashSet (S) | UnsafeParallelHashSet (S+B) | UnsafeParallelHashSet (B) | *HashSet w/lock (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(1, 0)`*¹* | 0.482ms   <span style="color:green">(9.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.115ms  <span style="color:green">(38.5x)</span>&nbsp;🟢 | 0.176ms  <span style="color:green">(25.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.301ms  <span style="color:green">(14.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.183ms  <span style="color:green">(24.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.171ms  <span style="color:green">(25.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *4.422ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(2, 0)`*¹˒²* | 0.244ms  <span style="color:green">(61.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.060ms <span style="color:green">(250.7x)</span>&nbsp;🟢 | 0.092ms <span style="color:green">(164.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.154ms  <span style="color:green">(98.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.091ms <span style="color:green">(166.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.086ms <span style="color:green">(175.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *15.041ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(4, 0)`*¹˒²* | 0.274ms <span style="color:green">(114.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.037ms <span style="color:green">(849.5x)</span>&nbsp;🟢 | 0.048ms <span style="color:green">(659.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.153ms <span style="color:green">(206.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.049ms <span style="color:green">(640.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.047ms <span style="color:green">(667.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *31.474ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(1, 100)`*¹* | 0.567ms   <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.128ms  <span style="color:green">(34.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.201ms  <span style="color:green">(22.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.401ms  <span style="color:green">(11.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.142ms  <span style="color:green">(31.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms  <span style="color:green">(40.9x)</span>&nbsp;🟢 | *4.424ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(2, 100)`*¹˒²* | 0.288ms  <span style="color:green">(52.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.068ms <span style="color:green">(221.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.105ms <span style="color:green">(143.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.217ms  <span style="color:green">(69.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.074ms <span style="color:green">(205.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.057ms <span style="color:green">(264.5x)</span>&nbsp;🟢 | *15.128ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `IsEmpty_x_100k(4, 100)`*¹˒²* | 0.315ms  <span style="color:green">(99.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.072ms <span style="color:green">(437.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.058ms <span style="color:green">(538.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.185ms <span style="color:green">(169.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.046ms <span style="color:green">(686.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.037ms <span style="color:green">(842.3x)</span>&nbsp;🟢 | *31.420ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(1, 0)`*¹* | 0.535ms   <span style="color:green">(8.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.201ms  <span style="color:green">(22.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms  <span style="color:green">(27.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.456ms   <span style="color:green">(9.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.181ms  <span style="color:green">(24.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms  <span style="color:green">(27.6x)</span>&nbsp;🟢 | *4.435ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(2, 0)`*¹˒²* | 0.271ms  <span style="color:green">(59.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.103ms <span style="color:green">(155.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.082ms <span style="color:green">(193.8x)</span>&nbsp;🟢 | 0.231ms  <span style="color:green">(69.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.093ms <span style="color:green">(171.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.083ms <span style="color:green">(192.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *15.965ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(4, 0)`*¹˒²* | 0.224ms <span style="color:green">(173.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.115ms <span style="color:green">(337.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.049ms <span style="color:green">(789.8x)</span>&nbsp;🟢 | 0.164ms <span style="color:green">(237.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.054ms <span style="color:green">(724.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.073ms <span style="color:green">(529.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *38.861ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(1, 100)`*¹* | 4.426ms   <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.620ms   <span style="color:green">(2.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.517ms   <span style="color:green">(2.9x)</span>&nbsp;🟢 | 3.323ms   <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.538ms   <span style="color:green">(2.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.268ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *4.438ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(2, 100)`*¹˒²* | 2.462ms   <span style="color:green">(6.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.020ms  <span style="color:green">(14.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.763ms  <span style="color:green">(19.9x)</span>&nbsp;🟢 | 1.683ms   <span style="color:green">(9.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.783ms  <span style="color:green">(19.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.824ms  <span style="color:green">(18.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *15.206ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Count_x_100k(4, 100)`*¹˒²* | 1.778ms  <span style="color:green">(18.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.848ms  <span style="color:green">(37.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.723ms  <span style="color:green">(44.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.556ms  <span style="color:green">(20.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.744ms  <span style="color:green">(43.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.665ms  <span style="color:green">(48.4x)</span>&nbsp;🟢 | *32.165ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArray(1, 10000)` | 0.039ms   <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.021ms   <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.038ms   <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.021ms   <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms   <span style="color:green">(1.9x)</span>&nbsp;🟢 | *0.018ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(1, 100000)` | 0.428ms   <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.202ms   <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms   <span style="color:green">(2.1x)</span>&nbsp;🟢 | 0.437ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.202ms   <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.084ms   <span style="color:green">(2.1x)</span>&nbsp;🟢 | *0.175ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(1, 1000000)` | 4.489ms   <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.192ms   <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.051ms   <span style="color:green">(1.9x)</span>&nbsp;🟢 | 4.690ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 2.187ms   <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.053ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.964ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Insert(1, 10000)` | 0.330ms  <span style="color:green">(11.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.188ms  <span style="color:green">(19.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.196ms  <span style="color:green">(19.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.301ms  <span style="color:green">(12.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.186ms  <span style="color:green">(20.0x)</span>&nbsp;🟢 | 0.202ms  <span style="color:green">(18.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.715ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 10000)`*²* | 0.468ms  <span style="color:green">(33.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.487ms  <span style="color:green">(31.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.264ms  <span style="color:green">(58.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.317ms  <span style="color:green">(49.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.260ms  <span style="color:green">(59.8x)</span>&nbsp;🟢 | 0.331ms  <span style="color:green">(47.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *15.537ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 10000)`*²* | 0.285ms <span style="color:green">(168.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.319ms <span style="color:green">(150.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.169ms <span style="color:green">(283.9x)</span>&nbsp;🟢 | 0.244ms <span style="color:green">(196.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.207ms <span style="color:green">(231.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.225ms <span style="color:green">(212.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *48.000ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1, 100000)` | 3.300ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.880ms   <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.957ms   <span style="color:green">(3.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.014ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.857ms   <span style="color:green">(3.2x)</span>&nbsp;🟢 | 2.079ms   <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *5.872ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 100000)`*²* | 4.849ms   <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.541ms   <span style="color:green">(3.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.555ms   <span style="color:green">(6.1x)</span>&nbsp;🟢 | 3.014ms   <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.288ms   <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.275ms   <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *15.510ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 100000)`*²* | 2.759ms  <span style="color:green">(16.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.462ms  <span style="color:green">(19.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.494ms  <span style="color:green">(31.3x)</span>&nbsp;🟢 | 2.236ms  <span style="color:green">(20.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.221ms  <span style="color:green">(21.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.804ms  <span style="color:green">(25.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *46.684ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(1, 1000000)` | 33.989ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.882ms   <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 20.803ms   <span style="color:green">(3.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 31.233ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 19.637ms   <span style="color:green">(3.1x)</span>&nbsp;🟢 | 20.789ms   <span style="color:green">(3.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *61.451ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(2, 1000000)`*²* | 48.854ms   <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 46.969ms   <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 27.594ms   <span style="color:green">(2.5x)</span>&nbsp;🟢 | 31.891ms   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 33.639ms   <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 35.067ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *70.068ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Insert(4, 1000000)`*²* | 32.946ms   <span style="color:green">(2.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 28.736ms   <span style="color:green">(3.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.753ms   <span style="color:green">(4.9x)</span>&nbsp;🟢 | 21.186ms   <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 24.702ms   <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 21.382ms   <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *91.349ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `AddGrow(1, 4, 1048576)`*³* | 36.009ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 12.228ms   <span style="color:green">(5.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.699ms   <span style="color:green">(5.6x)</span>&nbsp;🟢 | 34.592ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.898ms   <span style="color:green">(5.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.875ms   <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *65.912ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `AddGrow(1, 65536, 1048576)`*³* | 33.973ms   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.863ms   <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.247ms   <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 32.550ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.464ms   <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 11.203ms   <span style="color:green">(5.2x)</span>&nbsp;🟢 | *58.064ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 10000)` | 0.109ms   <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.019ms  <span style="color:green">(32.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.013ms  <span style="color:green">(47.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.095ms   <span style="color:green">(6.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms  <span style="color:green">(35.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.010ms  <span style="color:green">(60.2x)</span>&nbsp;🟢 | *0.611ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 10000)`*²* | 0.101ms <span style="color:green">(141.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.019ms <span style="color:green">(749.5x)</span>&nbsp;🟢 | 0.021ms <span style="color:green">(683.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.060ms <span style="color:green">(239.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.019ms <span style="color:green">(747.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.021ms <span style="color:green">(683.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *14.279ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 10000)`*²* | 0.098ms <span style="color:green">(128.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.031ms <span style="color:green">(402.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.023ms <span style="color:green">(559.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.057ms <span style="color:green">(219.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.021ms <span style="color:green">(607.8x)</span>&nbsp;🟢 | 0.022ms <span style="color:green">(561.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *12.582ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 100000)` | 1.531ms   <span style="color:green">(4.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.284ms  <span style="color:green">(24.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.191ms  <span style="color:green">(36.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.345ms   <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.300ms  <span style="color:green">(23.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.191ms  <span style="color:green">(36.9x)</span>&nbsp;🟢 | *7.043ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 100000)`*²* | 0.925ms  <span style="color:green">(23.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.225ms  <span style="color:green">(95.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.165ms <span style="color:green">(130.4x)</span>&nbsp;🟢 | 0.827ms  <span style="color:green">(26.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.227ms  <span style="color:green">(94.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.166ms <span style="color:green">(129.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *21.506ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 100000)`*²* | 0.717ms  <span style="color:green">(46.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.204ms <span style="color:green">(164.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.120ms <span style="color:green">(279.4x)</span>&nbsp;🟢 | 0.689ms  <span style="color:green">(48.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.389ms  <span style="color:green">(86.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.275ms <span style="color:green">(122.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *33.617ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(1, 1000000)` | 18.170ms   <span style="color:green">(4.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.754ms  <span style="color:green">(21.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.522ms  <span style="color:green">(32.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.496ms   <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.749ms  <span style="color:green">(21.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.491ms  <span style="color:green">(32.8x)</span>&nbsp;🟢 | *81.628ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(2, 1000000)`*²* | 11.131ms   <span style="color:green">(7.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.652ms  <span style="color:green">(32.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.045ms  <span style="color:green">(42.5x)</span>&nbsp;🟢 | 9.589ms   <span style="color:green">(9.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.733ms  <span style="color:green">(31.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.076ms  <span style="color:green">(41.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *86.828ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Contains(4, 1000000)`*²* | 8.584ms  <span style="color:green">(12.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 3.407ms  <span style="color:green">(32.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.220ms  <span style="color:green">(49.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 8.219ms  <span style="color:green">(13.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.053ms  <span style="color:green">(53.5x)</span>&nbsp;🟢 | 2.324ms  <span style="color:green">(47.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *109.936ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 10000)` | 0.139ms   <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.065ms   <span style="color:green">(9.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.059ms  <span style="color:green">(10.3x)</span>&nbsp;🟢 | 0.110ms   <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.061ms  <span style="color:green">(10.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.060ms  <span style="color:green">(10.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.611ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 100000)` | 1.694ms   <span style="color:green">(3.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.798ms   <span style="color:green">(8.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.689ms   <span style="color:green">(9.7x)</span>&nbsp;🟢 | 1.314ms   <span style="color:green">(5.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.707ms   <span style="color:green">(9.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.695ms   <span style="color:green">(9.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *6.684ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Remove(1, 1000000)` | 20.302ms   <span style="color:green">(3.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 9.389ms   <span style="color:green">(8.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.772ms   <span style="color:green">(9.7x)</span>&nbsp;🟢 | 15.004ms   <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 8.087ms   <span style="color:green">(9.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 7.788ms   <span style="color:green">(9.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *75.082ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(1, 10000)` | 0.097ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.024ms   <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.068ms   <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms   <span style="color:green">(2.0x)</span>&nbsp;🟢 | 0.018ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.035ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(1, 100000)` | 0.929ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.208ms   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.145ms   <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.605ms   <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.144ms   <span style="color:green">(2.4x)</span>&nbsp;🟢 | 0.144ms   <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.344ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(1, 1000000)` | 9.214ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 2.094ms   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.470ms   <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 5.994ms   <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.462ms   <span style="color:green">(2.5x)</span>&nbsp;🟢 | 1.491ms   <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.611ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `UnionWith(1, 10000)` | 0.539ms   <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.227ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.216ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.490ms   <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.214ms   <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.214ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.242ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `UnionWith(1, 100000)` | 5.532ms   <span style="color:red">(0.5x)</span>&nbsp;🟠 | 2.397ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.465ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 4.955ms   <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.263ms   <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.242ms   <span style="color:green">(1.2x)</span>&nbsp;🟢 | *2.687ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `UnionWith(1, 1000000)` | 79.156ms   <span style="color:red">(0.6x)</span>&nbsp;🟠 | 41.627ms   <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.230ms   <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 72.721ms   <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 36.150ms   <span style="color:green">(1.4x)</span>&nbsp;🟢 | 36.708ms   <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *48.928ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IntersectWith(1, 10000)` | 0.318ms   <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.135ms   <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.118ms   <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.264ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.110ms   <span style="color:green">(2.6x)</span>&nbsp;🟢 | 0.112ms   <span style="color:green">(2.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.286ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IntersectWith(1, 100000)` | 3.460ms   <span style="color:red">(0.9x)</span>&nbsp;🟠 | 1.490ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.322ms   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.881ms   <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.259ms   <span style="color:green">(2.4x)</span>&nbsp;🟢 | 1.280ms   <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *2.963ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IntersectWith(1, 1000000)` | 50.949ms   <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.330ms   <span style="color:green">(3.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 16.081ms   <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 41.292ms   <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 15.816ms   <span style="color:green">(4.1x)</span>&nbsp;🟢 | 15.828ms   <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *65.453ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ExceptWith(1, 10000)` | 0.269ms   <span style="color:red">(0.9x)</span>&nbsp;🟠 | 0.213ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.118ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.197ms   <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.115ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.112ms   <span style="color:green">(2.1x)</span>&nbsp;🟢 | *0.230ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ExceptWith(1, 100000)` | 2.960ms   <span style="color:red">(0.8x)</span>&nbsp;🟠 | 1.408ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.335ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.181ms   <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.320ms   <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.280ms   <span style="color:green">(1.9x)</span>&nbsp;🟢 | *2.467ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ExceptWith(1, 1000000)` | 40.054ms   <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 20.188ms   <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.223ms   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 30.004ms   <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 18.972ms   <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 17.592ms   <span style="color:green">(2.3x)</span>&nbsp;🟢 | *40.898ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*¹* Optimizations were disabled to perform this benchmark<br/>
*²* Benchmark run on parallel job workers - results may vary<br/>
*³* AddGrow(workers, capacity, growTo) -- Incrementally grows from `capacity` until reaching size of `growTo`<br/>
---
<br/>
### *QueueParallelWriter*
| Functionality | NativeQueueParallelWriter (S) | NativeQueueParallelWriter (S+B) | NativeQueueParallelWriter (B) | UnsafeQueueParallelWriter (S) | UnsafeQueueParallelWriter (S+B) | UnsafeQueueParallelWriter (B) | *ConcurrentQueue (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `EnqueueGrow(1, 10000)`*³* | 0.063ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.037ms   <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.027ms   <span style="color:green">(4.2x)</span>&nbsp;🟢 | --- | --- | --- | *0.112ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(2, 10000)`*²˒³* | 0.036ms   <span style="color:green">(3.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.032ms   <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.022ms   <span style="color:green">(6.3x)</span>&nbsp;🟢 | --- | --- | --- | *0.136ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(4, 10000)`*²˒³* | 0.041ms   <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.023ms   <span style="color:green">(9.1x)</span>&nbsp;🟢 | 0.028ms   <span style="color:green">(7.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *0.205ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(1, 100000)`*³* | 1.111ms   <span style="color:grey">(1.0x)</span>&nbsp;🟠 | 0.196ms   <span style="color:green">(5.5x)</span>&nbsp;🟢 | 0.249ms   <span style="color:green">(4.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *1.069ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `EnqueueGrow(2, 100000)`*²˒³* | 0.353ms  <span style="color:green">(43.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.129ms <span style="color:green">(118.3x)</span>&nbsp;🟢 | 0.141ms <span style="color:green">(107.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *15.233ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(4, 100000)`*²˒³* | 0.359ms <span style="color:green">(128.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.119ms <span style="color:green">(384.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.101ms <span style="color:green">(455.1x)</span>&nbsp;🟢 | --- | --- | --- | *45.962ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(1, 1000000)`*³* | 6.964ms   <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.971ms   <span style="color:green">(5.3x)</span>&nbsp;🟢 | 2.470ms   <span style="color:green">(4.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *10.493ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(2, 1000000)`*²˒³* | 3.587ms   <span style="color:green">(4.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.264ms  <span style="color:green">(12.0x)</span>&nbsp;🟢 | 1.353ms  <span style="color:green">(11.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *15.213ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(4, 1000000)`*²˒³* | 3.119ms  <span style="color:green">(14.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.036ms  <span style="color:green">(44.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.915ms  <span style="color:green">(50.7x)</span>&nbsp;🟢 | --- | --- | --- | *46.400ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(1, 10000)`*⁴* | 0.063ms   <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.014ms   <span style="color:green">(8.0x)</span>&nbsp;🟢 | 0.019ms   <span style="color:green">(5.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *0.112ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(2, 10000)`*²˒⁴* | 0.043ms   <span style="color:green">(3.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.015ms   <span style="color:green">(8.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.013ms  <span style="color:green">(10.1x)</span>&nbsp;🟢 | --- | --- | --- | *0.132ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(4, 10000)`*²˒⁴* | 0.036ms   <span style="color:green">(5.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms  <span style="color:green">(11.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.016ms  <span style="color:green">(13.0x)</span>&nbsp;🟢 | --- | --- | --- | *0.203ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(1, 100000)`*⁴* | 0.628ms   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.244ms   <span style="color:green">(4.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.187ms   <span style="color:green">(5.7x)</span>&nbsp;🟢 | --- | --- | --- | *1.068ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(2, 100000)`*²˒⁴* | 0.329ms  <span style="color:green">(46.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.142ms <span style="color:green">(107.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.107ms <span style="color:green">(142.5x)</span>&nbsp;🟢 | --- | --- | --- | *15.253ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(4, 100000)`*²˒⁴* | 0.305ms <span style="color:green">(154.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.077ms <span style="color:green">(611.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.061ms <span style="color:green">(767.5x)</span>&nbsp;🟢 | --- | --- | --- | *47.086ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(1, 1000000)`*⁴* | 6.283ms   <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.374ms   <span style="color:green">(7.6x)</span>&nbsp;🟢 | 1.869ms   <span style="color:green">(5.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *10.486ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(2, 1000000)`*²˒⁴* | 3.268ms   <span style="color:green">(4.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.896ms  <span style="color:green">(17.0x)</span>&nbsp;🟢 | 1.029ms  <span style="color:green">(14.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *15.201ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(4, 1000000)`*²˒⁴* | 2.931ms  <span style="color:green">(15.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.638ms  <span style="color:green">(72.4x)</span>&nbsp;🟢 | 0.697ms  <span style="color:green">(66.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | --- | --- | --- | *46.225ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*²* Benchmark run on parallel job workers - results may vary<br/>
*³* EnqueueGrow(workers, insertions)<br/>
*⁴* Enqueue(workers, insertions)<br/>
---
<br/>
### *Queue*
| Functionality | NativeQueue (S) | NativeQueue (S+B) | NativeQueue (B) | UnsafeQueue (S) | UnsafeQueue (S+B) | UnsafeQueue (B) | *Queue (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(0)`*¹* | 0.482ms  <span style="color:red">(0.2x)</span>&nbsp;🟠 | 0.181ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.232ms  <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.000ms  <span style="color:green">(334.3x)</span>&nbsp;🟢 | 0.000ms  <span style="color:green">(334.3x)</span>&nbsp;🟢 | *0.100ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IsEmpty_x_100k(100)`*¹* | 0.503ms  <span style="color:red">(0.2x)</span>&nbsp;🟠 | 0.188ms  <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.141ms  <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.241ms  <span style="color:red">(0.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.000ms  <span style="color:green">(334.3x)</span>&nbsp;🟢 | 0.000ms  <span style="color:green">(334.3x)</span>&nbsp;🟢 | *0.100ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(0)`*¹* | 0.313ms  <span style="color:red">(0.4x)</span>&nbsp;🟠 | 0.193ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.161ms  <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.189ms  <span style="color:red">(0.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.000ms  <span style="color:green">(401.2x)</span>&nbsp;🟢 | 0.000ms  <span style="color:green">(401.2x)</span>&nbsp;🟢 | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(100)`*¹* | 0.351ms  <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.181ms  <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.141ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.231ms  <span style="color:red">(0.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.000ms  <span style="color:green">(401.2x)</span>&nbsp;🟢 | 0.000ms  <span style="color:green">(343.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(10000)` | 0.003ms  <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms  <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms  <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms  <span style="color:green">(1.8x)</span>&nbsp;🟢 | 0.002ms    <span style="color:green">(1.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.002ms    <span style="color:green">(1.8x)</span>&nbsp;🟢 | *0.003ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `ToNativeArray(100000)` | 0.096ms  <span style="color:red">(0.3x)</span>&nbsp;🟠 | 0.016ms  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.015ms  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.089ms  <span style="color:red">(0.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.015ms    <span style="color:green">(1.9x)</span>&nbsp;🟢 | 0.015ms    <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.029ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `ToNativeArray(1000000)` | 0.991ms  <span style="color:red">(0.8x)</span>&nbsp;🟠 | 0.197ms  <span style="color:green">(4.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.163ms  <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.897ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.156ms    <span style="color:green">(5.2x)</span>&nbsp;🟢 | 0.161ms    <span style="color:green">(5.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.814ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `EnqueueGrow(10000)`*³* | 0.060ms <span style="color:green">(23.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.025ms <span style="color:green">(57.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.024ms <span style="color:green">(59.1x)</span>&nbsp;🟢 | 0.045ms <span style="color:green">(31.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.025ms   <span style="color:green">(56.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.026ms   <span style="color:green">(55.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *1.414ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `EnqueueGrow(100000)`*³* | 0.657ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.249ms  <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.231ms  <span style="color:green">(1.8x)</span>&nbsp;🟢 | 0.445ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.241ms    <span style="color:green">(1.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.248ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.407ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `EnqueueGrow(1000000)`*³* | 6.580ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 2.452ms  <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.340ms  <span style="color:green">(1.7x)</span>&nbsp;🟢 | 4.509ms  <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.473ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.509ms    <span style="color:green">(1.6x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.931ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Enqueue(10000)`*⁴* | 0.060ms  <span style="color:red">(0.8x)</span>&nbsp;🟠 | 0.019ms  <span style="color:green">(2.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms  <span style="color:green">(2.5x)</span>&nbsp;🟢 | 0.039ms  <span style="color:green">(1.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.020ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.020ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.046ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Enqueue(100000)`*⁴* | 0.599ms  <span style="color:red">(0.7x)</span>&nbsp;🟠 | 0.193ms  <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.180ms  <span style="color:green">(2.3x)</span>&nbsp;🟢 | 0.392ms  <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.198ms    <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.196ms    <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.407ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Enqueue(1000000)`*⁴* | 5.989ms  <span style="color:red">(0.7x)</span>&nbsp;🟠 | 2.048ms  <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.801ms  <span style="color:green">(2.2x)</span>&nbsp;🟢 | 3.933ms  <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.010ms    <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 2.011ms    <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.933ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Dequeue(10000)` | 0.066ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.025ms  <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.016ms  <span style="color:green">(2.4x)</span>&nbsp;🟢 | 0.045ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms    <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.037ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Dequeue(100000)` | 0.664ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.248ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.151ms  <span style="color:green">(2.4x)</span>&nbsp;🟢 | 0.455ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.158ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.159ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.369ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Dequeue(1000000)` | 6.640ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 2.479ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.503ms  <span style="color:green">(2.5x)</span>&nbsp;🟢 | 4.551ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.578ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.589ms    <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.690ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Peek(10000)`*¹* | 0.030ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.023ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.014ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.012ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.000ms   <span style="color:green">(45.4x)</span>&nbsp;🟢 | 0.000ms   <span style="color:green">(45.4x)</span>&nbsp;🟢 | *0.018ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Peek(100000)`*¹* | 0.302ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 0.222ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.134ms  <span style="color:green">(1.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.121ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.001ms  <span style="color:green">(278.8x)</span>&nbsp;🟢 | 0.001ms  <span style="color:green">(258.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.181ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Peek(1000000)`*¹* | 3.016ms  <span style="color:red">(0.6x)</span>&nbsp;🟠 | 2.213ms  <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.369ms  <span style="color:green">(1.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.205ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.001ms <span style="color:green">(2127.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.001ms <span style="color:green">(2260.8x)</span>&nbsp;🟢 | *1.809ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Foreach(10000)` | 0.028ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.009ms  <span style="color:green">(4.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.007ms  <span style="color:green">(6.4x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.003ms   <span style="color:green">(13.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.003ms   <span style="color:green">(14.1x)</span>&nbsp;🟢 | *0.042ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(100000)` | 0.283ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.082ms  <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.062ms  <span style="color:green">(6.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.182ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.027ms   <span style="color:green">(15.5x)</span>&nbsp;🟢 | 0.027ms   <span style="color:green">(15.5x)</span>&nbsp;🟢 | *0.425ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Foreach(1000000)` | 2.833ms  <span style="color:green">(1.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.812ms  <span style="color:green">(5.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.612ms  <span style="color:green">(6.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.819ms  <span style="color:green">(2.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.267ms   <span style="color:green">(15.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.267ms   <span style="color:green">(15.9x)</span>&nbsp;🟢 | *4.250ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*¹* Optimizations were disabled to perform this benchmark<br/>
*³* EnqueueGrow(insertions)<br/>
*⁴* Enqueue(insertions)<br/>
---
<br/>
### *RingQueue*
| Functionality | NativeRingQueue (S) | NativeRingQueue (S+B) | NativeRingQueue (B) | UnsafeRingQueue (S) | UnsafeRingQueue (S+B) | UnsafeRingQueue (B) | *Queue (BCL)* |
|---|--:|--:|--:|--:|--:|--:|--:|
| `IsEmpty_x_100k(0)`*¹* | 0.174ms <span style="color:red">(0.7x)</span>&nbsp;🟠 | 0.108ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.108ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.121ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.110ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.121ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `IsEmpty_x_100k(100)`*¹* | 0.161ms <span style="color:red">(0.8x)</span>&nbsp;🟠 | 0.108ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms <span style="color:green">(1.1x)</span>&nbsp;🟢 | 0.120ms <span style="color:grey">(1.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.110ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.120ms <span style="color:grey">(1.0x)</span>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
| `Count_x_100k(0)`*¹* | 0.192ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.142ms <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.108ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.120ms <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.101ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Count_x_100k(100)`*¹* | 0.188ms <span style="color:red">(0.5x)</span>&nbsp;🟠 | 0.143ms <span style="color:red">(0.7x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.110ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.120ms <span style="color:red">(0.8x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.111ms <span style="color:red">(0.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.100ms <span style="color:grey">(1.0x)</span>*&nbsp;🟢 |
| `Enqueue(10000)` | 0.033ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.019ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.018ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.019ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:green">(2.0x)</span>&nbsp;🟢 | 0.018ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.035ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(100000)` | 0.331ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.183ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.173ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.182ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.172ms <span style="color:green">(2.0x)</span>&nbsp;🟢 | 0.173ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.349ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Enqueue(1000000)` | 3.311ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.815ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.725ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.823ms <span style="color:green">(1.9x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.722ms <span style="color:green">(2.0x)</span>&nbsp;🟢 | 1.732ms <span style="color:green">(2.0x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.477ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Dequeue(10000)` | 0.032ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.008ms <span style="color:green">(4.6x)</span>&nbsp;🟢 | 0.017ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.017ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.011ms <span style="color:green">(3.3x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.035ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Dequeue(100000)` | 0.326ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.163ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.072ms <span style="color:green">(4.9x)</span>&nbsp;🟢 | 0.167ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.162ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.102ms <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *0.352ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
| `Dequeue(1000000)` | 3.257ms <span style="color:green">(1.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.624ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 0.708ms <span style="color:green">(5.0x)</span>&nbsp;🟢 | 1.666ms <span style="color:green">(2.1x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.612ms <span style="color:green">(2.2x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.008ms <span style="color:green">(3.5x)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | *3.516ms <span style="color:grey">(1.0x)</span>*&nbsp;🟠 |
*¹* Optimizations were disabled to perform this benchmark<br/>
---
@@ -0,0 +1,12 @@
# Performance comparisons
This section contains data around allocator and container performance benchmarks
|**Topic**|**Description**|
|---|---|
|[Allocator benchmarks](allocator-benchmarks.md)|Benchmark information for allocators.|
|[Container performance comparison](performance-comparison-containers.md)|Performance comparison for containers.|
## Additional resources
* [Allocator overview](allocation.md)
@@ -0,0 +1,5 @@
com.unity.collections copyright © 2024 Unity Technologies
Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license).
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 568f02fe7676e4d659782d6038df91de
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
# Unity.Collections
A C# collections library providing data structures that can be used in jobs, and
optimized by Burst compiler.
### Package CI Summary
[![](https://badge-proxy.cds.internal.unity3d.com/08bfbf8f-d0fc-4779-99bc-c492b6ac1c35)](https://badges.cds.internal.unity3d.com/packages/com.unity.collections/build-info?branch=master) [![](https://badge-proxy.cds.internal.unity3d.com/2d498c15-1aa6-41cf-aa34-b03b982e79ea)](https://badges.cds.internal.unity3d.com/packages/com.unity.collections/dependencies-info?branch=master) [![](https://badge-proxy.cds.internal.unity3d.com/52225b3e-e38b-4036-981d-8cb69c4ad20e)](https://badges.cds.internal.unity3d.com/packages/com.unity.collections/dependants-info) ![ReleaseBadge](https://badge-proxy.cds.internal.unity3d.com/5352b6f1-8596-433e-be1d-89f81a7fe619) ![ReleaseBadge](https://badge-proxy.cds.internal.unity3d.com/28dde859-48bb-4aa1-a1d0-a5a1d89885d5)
## Documentation
https://docs.unity3d.com/Packages/com.unity.collections@0.14/manual/index.html
## Data structures
The Unity.Collections package includes the following data structures:
Data structure | Description | Documentation
---------------------------- | ----------- | -------------
`BitField32` | Fixed size 32-bit array of bits. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.BitField32.html)
`BitField64` | Fixed size 64-bit array of bits. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.BitField64.html)
`NativeBitArray` | Arbitrary sized array of bits. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeBitArray.html)
`UnsafeBitArray` | Arbitrary sized array of bits, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeBitArray.html)
`NativeList` | An unmanaged, resizable list. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeList-1.html)
`UnsafeList` | An unmanaged, resizable list, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeList-1.html)
`NativeHashMap` | Unordered associative array, a collection of keys and values. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeHashMap-2.html)
`UnsafeHashMap` | Unordered associative array, a collection of keys and values, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeHashMap-2.html)
`NativeHashSet` | Set of values. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeHashSet-1.html)
`UnsafeHashSet` | Set of values, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeHashSet-1.html)
`NativeParallelHashMap` | Unordered associative array, a collection of keys and values. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeParallelHashMap-2.html)
`UnsafeParallelHashMap` | Unordered associative array, a collection of keys and values, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMap-2.html)
`NativeParallelHashSet` | Set of values. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeParallelHashSet-1.html)
`UnsafeParallelHashSet` | Set of values, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashSet-1.html)
`NativeParallelMultiHashMap` | Unordered associative array, a collection of keys and values. This container can store multiple values for every key. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeParallelMultiHashMap-2.html)
`UnsafeParallelMultiHashMap` | Unordered associative array, a collection of keys and values, without any thread safety check features. This container can store multiple values for every key. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeParallelMultiHashMap-2.html)
`NativeStream` | A deterministic data streaming supporting parallel reading and parallel writing. Allows you to write different types or arrays into a single stream. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeStream.html)
`UnsafeStream` | A deterministic data streaming supporting parallel reading and parallel writings, without any thread safety check features. Allows you to write different types or arrays into a single stream. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeStream.html)
`NativeReference` | An unmanaged, reference container. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.NativeReference-1.html)
`UnsafeAppendBuffer` | An unmanaged, untyped, buffer, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer.html)
`UnsafeRingQueue` | Fixed-size circular buffer, without any thread safety check features. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeRingQueue-1.html)
`UnsafeAtomicCounter32` | 32-bit atomic counter. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeAtomicCounter32.html)
`UnsafeAtomicCounter64` | 64-bit atomic counter. | [Documentation](https://docs.unity3d.com/Packages/com.unity.collections@0.14/api/Unity.Collections.LowLevel.Unsafe.UnsafeAtomicCounter64.html)
[...](https://docs.unity3d.com/Packages/com.unity.collections@0.14/manual/index.html)
The items in this package build upon the [NativeArray<T0>](https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1),
[NativeSlice<T0>](https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeSlice_1),
and other members of the Unity.Collections namespace, which Unity includes in
the [core module](https://docs.unity3d.com/ScriptReference/UnityEngine.CoreModule).
## Notation
`Native*` container prefix signifies that containers have debug safety mechanisms
which will warn users when a container is used incorrectly in regard with thread-safety,
or memory management. `Unsafe*` containers do not provide those safety warnings, and
the user is fully responsible to guarantee that code will execute correctly. Almost all
`Native*` containers are implemented by using `Unsafe*` container of the same kind
internally. In the release build, since debug safety mechanism is disabled, there
should not be any significant performance difference between `Unsafe*` and `Native*`
containers. `Unsafe*` containers are in `Unity.Collections.LowLevel.Unsafe`
namespace, while `Native*` containers are in `Unity.Collections` namespace.
## Determinism
Populating containers from parallel jobs is never deterministic, except when
using `NativeStream` or `UnsafeStream`. If determinism is required, consider
sorting the container as a separate step or post-process it on a single thread.
## Known Issues
All containers allocated with `Allocator.Temp` on the same thread use a shared
`AtomicSafetyHandle` instance. This is problematic when using `NativeParallelHashMap`,
`NativeParallelMultiHashMap`, `NativeParallelHashSet` and `NativeList` together in situations
where their secondary safety handle is used. This means that operations that
invalidate an enumerator for either of these collections (or the `NativeArray`
returned by `NativeList.AsArray`) will also invalidate all other previously
acquired enumerators. For example, this will throw when safety checks are enabled:
```
var list = new NativeList<int>(Allocator.Temp);
list.Add(1);
// This array uses the secondary safety handle of the list, which is
// shared between all Allocator.Temp allocations.
var array = list.AsArray();
var list2 = new NativeParallelHashSet<int>(Allocator.Temp);
// This invalidates the secondary safety handle, which is also used
// by the list above.
list2.TryAdd(1);
// This throws an InvalidOperationException because the shared safety
// handle was invalidated.
var x = array[0];
```
This defect will be addressed in a future release.
## Licensing
Unity Companion License (“License”) Software Copyright © 2017-2020 Unity Technologies ApS
For licensing details see [LICENSE.md](LICENSE.md)
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: af5aad29a2c56fd449428c9041fc68bb
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 00a9bcd29d03e5043aad0c9a7e6185f3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d503f3e3b7fd2147a8ddc4135fcc0e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
{
"name": "Unity.Collections.BurstCompatibilityGen",
"references": [
"Unity.Burst",
"Unity.Collections"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4f5c0c83dfd6a0743834baba2b4de79e
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d44454e6d25878e46a8495f8a720d7c0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
using Mono.Cecil;
namespace Unity.Jobs.CodeGen
{
static class TypeReferenceExtensions
{
public static TypeDefinition CheckedResolve(this TypeReference typeReference)
{
return typeReference.Resolve() ?? throw new ResolutionException(typeReference);
}
}
static class MethodReferenceExtensions
{
/// <summary>
/// Generates a closed/specialized MethodReference for the given method and types[]
/// e.g.
/// struct Foo { T Bar<T>(T val) { return default(T); }
///
/// In this case, if one would like a reference to "Foo::int Bar(int val)" this method will construct such a method
/// reference when provided the open "T Bar(T val)" method reference and the TypeReferences to the types you'd like
/// specified as generic arguments (in this case a TypeReference to "int" would be passed in).
/// </summary>
/// <param name="method"></param>
/// <param name="types"></param>
/// <returns></returns>
public static MethodReference MakeGenericInstanceMethod(this MethodReference method,
params TypeReference[] types)
{
var result = new GenericInstanceMethod(method);
foreach (var type in types)
result.GenericArguments.Add(type);
return result;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3e09463226731fa409854248a8059507
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,418 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Unity.CompilationPipeline.Common.ILPostProcessing;
using Unity.Jobs.LowLevel.Unsafe;
using MethodAttributes = Mono.Cecil.MethodAttributes;
using MethodBody = Mono.Cecil.Cil.MethodBody;
using TypeAttributes = Mono.Cecil.TypeAttributes;
namespace Unity.Jobs.CodeGen
{
internal partial class JobsILPostProcessor : ILPostProcessor
{
private static readonly string ProducerAttributeName = typeof(JobProducerTypeAttribute).FullName;
private static readonly string RegisterGenericJobTypeAttributeName = typeof(RegisterGenericJobTypeAttribute).FullName;
public static MethodReference AttributeConstructorReferenceFor(Type attributeType, ModuleDefinition module)
{
return module.ImportReference(attributeType.GetConstructor(Array.Empty<Type>()));
}
private TypeReference LaunderTypeRef(TypeReference r_)
{
ModuleDefinition mod = AssemblyDefinition.MainModule;
TypeDefinition def = r_.Resolve();
TypeReference result;
if (r_ is GenericInstanceType git)
{
var gt = new GenericInstanceType(LaunderTypeRef(def));
foreach (var gp in git.GenericParameters)
{
gt.GenericParameters.Add(gp);
}
foreach (var ga in git.GenericArguments)
{
gt.GenericArguments.Add(LaunderTypeRef(ga));
}
result = gt;
}
else
{
result = new TypeReference(def.Namespace, def.Name, def.Module, def.Scope, def.IsValueType);
if (def.DeclaringType != null)
{
result.DeclaringType = LaunderTypeRef(def.DeclaringType);
}
}
return mod.ImportReference(result);
}
// http://www.isthe.com/chongo/src/fnv/hash_64a.c
static ulong StableHash_FNV1A64(string text)
{
ulong result = 14695981039346656037;
foreach (var c in text)
{
result = 1099511628211 * (result ^ (byte)(c & 255));
result = 1099511628211 * (result ^ (byte)(c >> 8));
}
return result;
}
bool PostProcessImpl()
{
bool anythingChanged = false;
var asmDef = AssemblyDefinition;
var funcDef = new MethodDefinition("CreateJobReflectionData",
MethodAttributes.Static | MethodAttributes.Public | MethodAttributes.HideBySig,
asmDef.MainModule.ImportReference(typeof(void)));
// This must use a stable hash code function (do not using string.GetHashCode)
var autoClassName = $"__JobReflectionRegistrationOutput__{StableHash_FNV1A64(asmDef.FullName)}";
funcDef.Body.InitLocals = false;
var classDef = new TypeDefinition("", autoClassName, TypeAttributes.Class, asmDef.MainModule.ImportReference(typeof(object)));
classDef.IsBeforeFieldInit = false;
classDef.CustomAttributes.Add(new CustomAttribute(AttributeConstructorReferenceFor(typeof(DOTSCompilerGeneratedAttribute), asmDef.MainModule)));
classDef.Methods.Add(funcDef);
var body = funcDef.Body;
var processor = body.GetILProcessor();
// Setup instructions used for try/catch wrapping all earlyinit calls
// for this assembly's job types
var workStartOp = processor.Create(OpCodes.Nop);
var workDoneOp = Instruction.Create(OpCodes.Nop);
var handler = Instruction.Create(OpCodes.Nop);
var landingPad = Instruction.Create(OpCodes.Nop);
processor.Append(workStartOp);
var genericJobs = new List<TypeReference>();
var visited = new HashSet<string>();
foreach (var attr in asmDef.CustomAttributes)
{
if (attr.AttributeType.FullName != RegisterGenericJobTypeAttributeName)
continue;
var typeRef = (TypeReference)attr.ConstructorArguments[0].Value;
var openType = typeRef.Resolve();
if (!typeRef.IsGenericInstance || !openType.IsValueType)
{
DiagnosticMessages.Add(UserError.DC3001(openType));
continue;
}
genericJobs.Add(typeRef);
visited.Add(typeRef.FullName);
}
CollectGenericTypeInstances(AssemblyDefinition, genericJobs, visited);
foreach (var t in asmDef.MainModule.Types)
{
anythingChanged |= VisitJobStructs(t, processor, body);
}
foreach (var t in genericJobs)
{
anythingChanged |= VisitJobStructs(t, processor, body);
}
// Now that we have generated all reflection info
// finish wrapping the ops in a try catch now
var lastWorkOp = processor.Body.Instructions[processor.Body.Instructions.Count-1];
processor.Append(handler);
var earlyInitHelpersDef = asmDef.MainModule.ImportReference(typeof(EarlyInitHelpers)).Resolve();
MethodDefinition jobReflectionDataCreationFailedDef = null;
foreach (var method in earlyInitHelpersDef.Methods)
{
if (method.Name == nameof(EarlyInitHelpers.JobReflectionDataCreationFailed))
{
jobReflectionDataCreationFailedDef = method;
break;
}
}
var errorHandler = asmDef.MainModule.ImportReference(jobReflectionDataCreationFailedDef);
processor.Append(Instruction.Create(OpCodes.Call, errorHandler));
processor.Append(landingPad);
var leaveSuccess = Instruction.Create(OpCodes.Leave, landingPad);
var leaveFail = Instruction.Create(OpCodes.Leave, landingPad);
processor.InsertAfter(lastWorkOp, leaveSuccess);
processor.InsertBefore(landingPad, leaveFail);
var exc = new ExceptionHandler(ExceptionHandlerType.Catch);
exc.TryStart = workStartOp;
exc.TryEnd = leaveSuccess.Next;
exc.HandlerStart = handler;
exc.HandlerEnd = leaveFail.Next;
exc.CatchType = asmDef.MainModule.ImportReference(typeof(Exception));
body.ExceptionHandlers.Add(exc);
processor.Emit(OpCodes.Ret);
if (anythingChanged)
{
var ctorFuncDef = new MethodDefinition("EarlyInit", MethodAttributes.Static | MethodAttributes.Public | MethodAttributes.HideBySig, asmDef.MainModule.ImportReference(typeof(void)));
if (!Defines.Contains("UNITY_EDITOR"))
{
// Needs to run automatically in the player, but we need to
// exclude this attribute when building for the editor, or
// it will re-run the registration for every enter play mode.
var loadTypeEnumType = asmDef.MainModule.ImportReference(typeof(UnityEngine.RuntimeInitializeLoadType));
var attributeCtor = asmDef.MainModule.ImportReference(typeof(UnityEngine.RuntimeInitializeOnLoadMethodAttribute).GetConstructor(new[] { typeof(UnityEngine.RuntimeInitializeLoadType) }));
var attribute = new CustomAttribute(attributeCtor);
attribute.ConstructorArguments.Add(new CustomAttributeArgument(loadTypeEnumType, UnityEngine.RuntimeInitializeLoadType.AfterAssembliesLoaded));
ctorFuncDef.CustomAttributes.Add(attribute);
}
else
{
// Needs to run automatically in the editor.
var attributeCtor2 = asmDef.MainModule.ImportReference(typeof(UnityEditor.InitializeOnLoadMethodAttribute).GetConstructor(Type.EmptyTypes));
ctorFuncDef.CustomAttributes.Add(new CustomAttribute(attributeCtor2));
}
ctorFuncDef.Body.InitLocals = false;
var p = ctorFuncDef.Body.GetILProcessor();
p.Emit(OpCodes.Call, funcDef);
p.Emit(OpCodes.Ret);
classDef.Methods.Add(ctorFuncDef);
asmDef.MainModule.Types.Add(classDef);
}
return anythingChanged;
}
private bool VisitJobStructInterfaces(TypeReference jobTypeRef, TypeDefinition jobType, TypeDefinition currentType, ILProcessor processor, MethodBody body)
{
bool didAnything = false;
if (currentType.HasInterfaces && jobType.IsValueType)
{
foreach (var iface in currentType.Interfaces)
{
var idef = iface.InterfaceType.CheckedResolve();
foreach (var attr in idef.CustomAttributes)
{
if (attr.AttributeType.FullName == ProducerAttributeName)
{
var producerRef = (TypeReference)attr.ConstructorArguments[0].Value;
var launderedType = LaunderTypeRef(jobTypeRef);
didAnything |= GenerateCalls(producerRef, launderedType, body, processor);
}
if (currentType.IsInterface)
{
// Generic jobs need to be either reference in fully closed form, or registered explicitly with an attribute.
if (iface.InterfaceType.GenericParameters.Count == 0)
didAnything |= VisitJobStructInterfaces(jobTypeRef, jobType, idef, processor, body);
}
}
}
}
foreach (var nestedType in currentType.NestedTypes)
{
didAnything |= VisitJobStructs(nestedType, processor, body);
}
return didAnything;
}
private bool VisitJobStructs(TypeReference t, ILProcessor processor, MethodBody body)
{
if (t.GenericParameters.Count > 0)
{
// Generic jobs need to be either reference in fully closed form, or registered explicitly with an attribute.
return false;
}
var rt = t.CheckedResolve();
return VisitJobStructInterfaces(t, rt, rt, processor, body);
}
private bool GenerateCalls(TypeReference producerRef, TypeReference jobStructType, MethodBody body, ILProcessor processor)
{
try
{
var carrierType = producerRef.CheckedResolve();
MethodDefinition methodToCall = null;
while (carrierType != null)
{
methodToCall = null;
foreach (var method in carrierType.GetMethods())
{
if(method.IsStatic && method.IsPublic && method.Parameters.Count == 0 && method.Name == "EarlyJobInit")
{
methodToCall = method;
break;
}
}
if (methodToCall != null)
break;
carrierType = carrierType.DeclaringType;
}
// Legacy jobs lazy initialize.
if (methodToCall == null)
return false;
var asm = AssemblyDefinition.MainModule;
var mref = asm.ImportReference(asm.ImportReference(methodToCall).MakeGenericInstanceMethod(jobStructType));
// Make sure the job type is accessable to the generated CreateJobReflectionData at the assembly root
MakeTypeAccessableToAssembly(jobStructType);
// Make sure any types used as GenericArguments are also accessable
if (jobStructType is GenericInstanceType genericInstance)
{
foreach (var g in genericInstance.GenericArguments)
{
MakeTypeAccessableToAssembly(g);
}
}
processor.Append(Instruction.Create(OpCodes.Call, mref));
return true;
}
catch (Exception ex)
{
DiagnosticMessages.Add(InternalCompilerError.DCICE300(producerRef, jobStructType, ex));
}
return false;
}
static void MakeTypeAccessableToAssembly(TypeReference type)
{
while (type != null)
{
var typeDefinition = type.CheckedResolve();
if (typeDefinition.IsNestedPrivate || typeDefinition.IsNestedFamily)
{
typeDefinition.IsNestedAssembly = true;
}
type = typeDefinition.DeclaringType;
}
}
private static void CollectGenericTypeInstances(AssemblyDefinition assembly, List<TypeReference> types, HashSet<string> visited)
{
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// WARNING: THIS CODE HAS TO BE MAINTAINED IN SYNC WITH BurstReflection.cs in Unity.Burst package
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// From: https://gist.github.com/xoofx/710aaf86e0e8c81649d1261b1ef9590e
if (assembly == null) throw new ArgumentNullException(nameof(assembly));
const int mdMaxCount = 1 << 24;
foreach (var module in assembly.Modules)
{
for (int i = 1; i < mdMaxCount; i++)
{
// Token base id for TypeSpec
const int mdTypeSpec = 0x1B000000;
var token = module.LookupToken(mdTypeSpec | i);
if (token is GenericInstanceType type)
{
if (type.IsGenericInstance && !type.ContainsGenericParameter)
{
CollectGenericTypeInstances(type, types, visited);
}
} else if (token == null) break;
}
for (int i = 1; i < mdMaxCount; i++)
{
// Token base id for MethodSpec
const int mdMethodSpec = 0x2B000000;
var token = module.LookupToken(mdMethodSpec | i);
if (token is GenericInstanceMethod method)
{
foreach (var argType in method.GenericArguments)
{
if (argType.IsGenericInstance && !argType.ContainsGenericParameter)
{
CollectGenericTypeInstances(argType, types, visited);
}
}
}
else if (token == null) break;
}
for (int i = 1; i < mdMaxCount; i++)
{
// Token base id for Field
const int mdField = 0x04000000;
var token = module.LookupToken(mdField | i);
if (token is FieldReference field)
{
var fieldType = field.FieldType;
if (fieldType.IsGenericInstance && !fieldType.ContainsGenericParameter)
{
CollectGenericTypeInstances(fieldType, types, visited);
}
}
else if (token == null) break;
}
}
}
private static void CollectGenericTypeInstances(TypeReference type, List<TypeReference> types, HashSet<string> visited)
{
if (type.IsPrimitive) return;
if (!visited.Add(type.FullName)) return;
// Add only concrete types
if (type.IsGenericInstance && !type.ContainsGenericParameter)
{
types.Add(type);
}
// Collect recursively generic type arguments
var genericInstanceType = type as GenericInstanceType;
if (genericInstanceType != null)
{
foreach (var genericTypeArgument in genericInstanceType.GenericArguments)
{
if (!genericTypeArgument.IsPrimitive)
{
CollectGenericTypeInstances(genericTypeArgument, types, visited);
}
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 303e5975f34d18c4d81f25c4af12839a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,335 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Unity.CompilationPipeline.Common.Diagnostics;
using Unity.CompilationPipeline.Common.ILPostProcessing;
namespace Unity.Jobs.CodeGen
{
// Jobs ILPP entry point
internal partial class JobsILPostProcessor : ILPostProcessor
{
AssemblyDefinition AssemblyDefinition;
List<DiagnosticMessage> DiagnosticMessages = new List<DiagnosticMessage>();
public HashSet<string> Defines { get; private set; }
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
{
bool madeAnyChange = false;
Defines = new HashSet<string>(compiledAssembly.Defines);
try
{
AssemblyDefinition = AssemblyDefinitionFor(compiledAssembly);
}
catch (BadImageFormatException)
{
return new ILPostProcessResult(null, DiagnosticMessages);
}
try
{
// This only works because the PostProcessorAssemblyResolver is explicitly loading
// transitive dependencies (and then some) and so if we can't find a references to
// Unity.Jobs (via EarlyInitHelpers) in there than we are confident the assembly doesn't need processing
var earlyInitHelpers = AssemblyDefinition.MainModule.ImportReference(typeof(EarlyInitHelpers)).CheckedResolve();
}
catch (ResolutionException)
{
return new ILPostProcessResult(null, DiagnosticMessages);
}
madeAnyChange = PostProcessImpl();
// Hack to remove circular references
var selfName = AssemblyDefinition.Name.FullName;
foreach (var referenceName in AssemblyDefinition.MainModule.AssemblyReferences)
{
if (referenceName.FullName == selfName)
{
AssemblyDefinition.MainModule.AssemblyReferences.Remove(referenceName);
break;
}
}
if (!madeAnyChange)
return new ILPostProcessResult(null, DiagnosticMessages);
bool hasError = false;
foreach (var d in DiagnosticMessages)
{
if (d.DiagnosticType == DiagnosticType.Error)
{
hasError = true;
break;
}
}
if (hasError)
return new ILPostProcessResult(null, DiagnosticMessages);
var pe = new MemoryStream();
var pdb = new MemoryStream();
var writerParameters = new WriterParameters
{
SymbolWriterProvider = new PortablePdbWriterProvider(), SymbolStream = pdb, WriteSymbols = true
};
AssemblyDefinition.Write(pe, writerParameters);
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), DiagnosticMessages);
}
public override ILPostProcessor GetInstance()
{
return this;
}
public override bool WillProcess(ICompiledAssembly compiledAssembly)
{
if (compiledAssembly.Name.EndsWith("CodeGen.Tests", StringComparison.Ordinal))
return false;
if (compiledAssembly.InMemoryAssembly.PdbData == null || compiledAssembly.InMemoryAssembly.PeData == null)
return false;
var referencesCollections = false;
if (compiledAssembly.Name == "Unity.Collections")
{
return true;
}
for (int i = 0; i < compiledAssembly.References.Length; ++i)
{
var fileName = Path.GetFileNameWithoutExtension(compiledAssembly.References[i]);
if (fileName == "Unity.Collections")
{
referencesCollections = true;
break;
}
}
if (!referencesCollections) return false;
return true;
}
// *******************************************************************************
// ** NOTE
// ** Everything below this is a copy of the same process used in EntitiesILPostProcessor and
// ** should stay synced with it.
// *******************************************************************************
class PostProcessorAssemblyResolver : IAssemblyResolver
{
private readonly HashSet<string> _referenceDirectories;
private Dictionary<string, HashSet<string>> _referenceToPathMap;
Dictionary<string, AssemblyDefinition> _cache = new Dictionary<string, AssemblyDefinition>();
private ICompiledAssembly _compiledAssembly;
private AssemblyDefinition _selfAssembly;
public PostProcessorAssemblyResolver(ICompiledAssembly compiledAssembly)
{
_compiledAssembly = compiledAssembly;
_referenceToPathMap = new Dictionary<string, HashSet<string>>();
_referenceDirectories = new HashSet<string>();
foreach (var reference in compiledAssembly.References)
{
var assemblyName = Path.GetFileNameWithoutExtension(reference);
if (!_referenceToPathMap.TryGetValue(assemblyName, out var fileList))
{
fileList = new HashSet<string>();
_referenceToPathMap.Add(assemblyName, fileList);
}
fileList.Add(reference);
_referenceDirectories.Add(Path.GetDirectoryName(reference));
}
}
public void Dispose()
{
}
public AssemblyDefinition Resolve(AssemblyNameReference name)
{
return Resolve(name, new ReaderParameters(ReadingMode.Deferred));
}
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
{
if (name.Name == _compiledAssembly.Name)
return _selfAssembly;
var fileName = FindFile(name);
if (fileName == null)
return null;
var cacheKey = fileName;
if (_cache.TryGetValue(cacheKey, out var result))
return result;
parameters.AssemblyResolver = this;
var ms = MemoryStreamFor(fileName);
var pdb = fileName + ".pdb";
if (File.Exists(pdb))
parameters.SymbolStream = MemoryStreamFor(pdb);
var assemblyDefinition = AssemblyDefinition.ReadAssembly(ms, parameters);
_cache.Add(cacheKey, assemblyDefinition);
return assemblyDefinition;
}
}
private string FindFile(AssemblyNameReference name)
{
if (_referenceToPathMap.TryGetValue(name.Name, out var paths))
{
if (paths.Count == 1)
{
var enumerator = paths.GetEnumerator();
// enumerators begin before the first element
enumerator.MoveNext();
return enumerator.Current;
}
// If we have more than one assembly with the same name loaded we now need to figure out which one
// is being requested based on the AssemblyNameReference
foreach (var path in paths)
{
var onDiskAssemblyName = AssemblyName.GetAssemblyName(path);
if (onDiskAssemblyName.FullName == name.FullName)
return path;
}
throw new ArgumentException($"Tried to resolve a reference in assembly '{name.FullName}' however the assembly could not be found. Known references which did not match: \n{string.Join("\n",paths)}");
}
// Unfortunately the current ICompiledAssembly API only provides direct references.
// It is very much possible that a postprocessor ends up investigating a type in a directly
// referenced assembly, that contains a field that is not in a directly referenced assembly.
// if we don't do anything special for that situation, it will fail to resolve. We should fix this
// in the ILPostProcessing api. As a workaround, we rely on the fact here that the indirect references
// are always located next to direct references, so we search in all directories of direct references we
// got passed, and if we find the file in there, we resolve to it.
foreach (var parentDir in _referenceDirectories)
{
var candidate = Path.Combine(parentDir, name.Name + ".dll");
if (File.Exists(candidate))
{
if (!_referenceToPathMap.TryGetValue(candidate, out var referencePaths))
{
referencePaths = new HashSet<string>();
_referenceToPathMap.Add(candidate, referencePaths);
}
referencePaths.Add(candidate);
return candidate;
}
}
return null;
}
static MemoryStream MemoryStreamFor(string fileName)
{
return Retry(10, TimeSpan.FromSeconds(1), () => {
byte[] byteArray;
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
byteArray = new byte[fs.Length];
var readLength = fs.Read(byteArray, 0, (int)fs.Length);
if (readLength != fs.Length)
throw new InvalidOperationException("File read length is not full length of file.");
}
return new MemoryStream(byteArray);
});
}
private static MemoryStream Retry(int retryCount, TimeSpan waitTime, Func<MemoryStream> func)
{
try
{
return func();
}
catch (IOException)
{
if (retryCount == 0)
throw;
Console.WriteLine($"Caught IO Exception, trying {retryCount} more times");
Thread.Sleep(waitTime);
return Retry(retryCount - 1, waitTime, func);
}
}
public void AddAssemblyDefinitionBeingOperatedOn(AssemblyDefinition assemblyDefinition)
{
_selfAssembly = assemblyDefinition;
}
}
internal static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compiledAssembly)
{
var resolver = new PostProcessorAssemblyResolver(compiledAssembly);
var readerParameters = new ReaderParameters
{
SymbolStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PdbData),
SymbolReaderProvider = new PortablePdbReaderProvider(),
AssemblyResolver = resolver,
ReflectionImporterProvider = new PostProcessorReflectionImporterProvider(),
ReadingMode = ReadingMode.Immediate
};
var peStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PeData);
var assemblyDefinition = AssemblyDefinition.ReadAssembly(peStream, readerParameters);
//apparently, it will happen that when we ask to resolve a type that lives inside Unity.Jobs, and we
//are also postprocessing Unity.Jobs, type resolving will fail, because we do not actually try to resolve
//inside the assembly we are processing. Let's make sure we do that, so that we can use postprocessor features inside
//unity.Jobs itself as well.
resolver.AddAssemblyDefinitionBeingOperatedOn(assemblyDefinition);
return assemblyDefinition;
}
}
internal class PostProcessorReflectionImporterProvider : IReflectionImporterProvider
{
public IReflectionImporter GetReflectionImporter(ModuleDefinition module)
{
return new PostProcessorReflectionImporter(module);
}
}
internal class PostProcessorReflectionImporter : DefaultReflectionImporter
{
private const string SystemPrivateCoreLib = "System.Private.CoreLib";
private AssemblyNameReference _correctCorlib;
public PostProcessorReflectionImporter(ModuleDefinition module) : base(module)
{
_correctCorlib = default;
foreach (var a in module.AssemblyReferences)
{
if (a.Name == "mscorlib" || a.Name == "netstandard" || a.Name == SystemPrivateCoreLib)
{
_correctCorlib = a;
break;
}
}
}
public override AssemblyNameReference ImportReference(AssemblyName reference)
{
if (_correctCorlib != null && reference.Name == SystemPrivateCoreLib)
return _correctCorlib;
return base.ImportReference(reference);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b544eddbc9bfd24fad9da6ddbe65962
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
{
"name": "Unity.Collections.CodeGen",
"references": [
"Unity.Burst",
"Unity.Collections",
"Unity.Properties"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"Mono.Cecil.dll",
"Mono.Cecil.Rocks.dll",
"Mono.Cecil.Pdb.dll",
"Unity.IL2CPP",
"Unity.IL2CPP.Common"
],
"autoReferenced": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8baa6eabecd47164e94a1eb92b18f394
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Unity.CompilationPipeline.Common.Diagnostics;
namespace Unity.Jobs.CodeGen
{
static class InternalCompilerError
{
public static DiagnosticMessage DCICE300(TypeReference producerReference, TypeReference jobStructType, Exception ex)
{
return UserError.MakeError(nameof(DCICE300), $"Unexpected error while generating automatic registration for job provider {producerReference.FullName} via job struct {jobStructType.FullName}. Please report this error.\nException: {ex.Message}");
}
}
static class UserError
{
public static DiagnosticMessage DC3001(TypeReference type)
{
return MakeError(nameof(DC3001), $"{type.FullName}: [RegisterGenericJobType] requires an instance of a generic value type");
}
static DiagnosticMessage MakeInternal(DiagnosticType type, string errorCode, string messageData)
{
var result = new DiagnosticMessage {Column = 0, Line = 0, DiagnosticType = type, File = ""};
if (errorCode.Contains("ICE"))
{
messageData = messageData + " Seeing this error indicates a bug in the DOTS Job code-generators. We'd appreciate a bug report (About->Report a Bug...). Thnx! <3";
}
var errorType = type == DiagnosticType.Error ? "error" : "warning";
messageData = $"{errorType} {errorCode}: {messageData}";
result.MessageData = messageData;
return result;
}
public static DiagnosticMessage MakeError(string errorCode, string messageData)
{
return MakeInternal(DiagnosticType.Error, errorCode, messageData);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2d53df25c7f81aa419ea121140c42d6b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d1e9e4c1f536d9246ac795d9abc62342
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System;
using UnityEditor;
using Unity.Collections;
using UnityEngine;
class CLILeakDetectionSwitcher
{
[InitializeOnLoadMethod]
static void SetLeakDetectionModeFromEnvironment()
{
var nativeLeakDetectionMode = Environment.GetEnvironmentVariable("UNITY_JOBS_NATIVE_LEAK_DETECTION_MODE");
if (!string.IsNullOrEmpty(nativeLeakDetectionMode))
{
switch (nativeLeakDetectionMode)
{
case "0":
NativeLeakDetection.Mode = NativeLeakDetectionMode.Disabled;
break;
case "1":
NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
break;
case "2":
NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;
break;
default:
Debug.LogWarning("The environment variable UNITY_JOBS_NATIVE_LEAK_DETECTION_MODE has an invalid value. Please use: 0 = Disabled, 1 = Enabled, 2 = EnabledWithStackTrace.");
break;
}
Debug.Log("Native leak detection mode: " + NativeLeakDetection.Mode);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a3b018ffc4586a441a093c4d954a8cf1
timeCreated: 1507328300
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
using System;
using UnityEditor;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs.LowLevel.Unsafe;
using UnityEngine;
// This menu is available from the editor directly on later versions
#if !UNITY_2022_2_14F1_OR_NEWER
class JobsMenu
{
private static int savedJobWorkerCount = JobsUtility.JobWorkerCount;
[SettingsProvider]
private static SettingsProvider JobsPreferencesItem()
{
var provider = new SettingsProvider("Preferences/Jobs", SettingsScope.User)
{
label = "Jobs",
keywords = new[]{"Jobs"},
guiHandler = (searchContext) =>
{
var originalWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 200f;
EditorGUILayout.BeginVertical();
GUILayout.BeginVertical();
EditorGUILayout.LabelField("For safety, these values are reset on editor restart.");
bool madeChange = false;
bool oldWorkerCount = (JobsUtility.JobWorkerCount > 0);
bool newWorkerCount = EditorGUILayout.Toggle(new GUIContent("Use Job Threads:"), oldWorkerCount);
if (newWorkerCount != oldWorkerCount)
{
madeChange = true;
SwitchUseJobThreads();
}
bool oldUseJobsDebugger = JobsUtility.JobDebuggerEnabled;
var newUseJobsDebugger = EditorGUILayout.Toggle(new GUIContent("Enable Jobs Debugger"), JobsUtility.JobDebuggerEnabled);
if (newUseJobsDebugger != oldUseJobsDebugger)
{
madeChange = true;
SetUseJobsDebugger(newUseJobsDebugger);
}
var oldLeakDetectionMode = NativeLeakDetection.Mode;
var newLeakDetectionMode = (NativeLeakDetectionMode) EditorGUILayout.EnumPopup(new GUIContent("Leak Detection Level"), oldLeakDetectionMode);
if (newLeakDetectionMode != oldLeakDetectionMode)
{
madeChange = true;
SetLeakDetection(newLeakDetectionMode);
}
if (madeChange)
Telemetry.LogMenuPreferences(new Telemetry.MenuPreferencesEvent { useJobsThreads = newUseJobsDebugger, enableJobsDebugger = newUseJobsDebugger, nativeLeakDetectionMode = newLeakDetectionMode });
GUILayout.EndVertical();
EditorGUILayout.EndVertical();
EditorGUIUtility.labelWidth = originalWidth;
}
};
return provider;
}
static void SwitchUseJobThreads()
{
if (JobsUtility.JobWorkerCount > 0)
{
savedJobWorkerCount = JobsUtility.JobWorkerCount;
JobsUtility.JobWorkerCount = 0;
}
else
{
JobsUtility.JobWorkerCount = savedJobWorkerCount;
if (savedJobWorkerCount == 0)
{
JobsUtility.ResetJobWorkerCount();
}
}
}
static void SetUseJobsDebugger(bool value)
{
JobsUtility.JobDebuggerEnabled = value;
}
static void SetLeakDetection(NativeLeakDetectionMode value)
{
switch(value)
{
case NativeLeakDetectionMode.Disabled:
{
// In the case where someone enables, disables, then re-enables leak checking, we might miss some frees
// while disabled. So to avoid spurious leak warnings, just forgive the leaks every time someone disables
// leak checking through the menu.
UnsafeUtility.ForgiveLeaks();
Debug.LogWarning("Leak detection has been disabled. Leak warnings will not be generated, and all leaks up to now are forgotten.");
break;
}
case NativeLeakDetectionMode.Enabled:
{
Debug.Log("Leak detection has been enabled. Leak warnings will be generated upon exiting play mode.");
break;
}
case NativeLeakDetectionMode.EnabledWithStackTrace:
{
Debug.Log("Leak detection with stack traces has been enabled. Leak warnings will be generated upon exiting play mode.");
break;
}
default:
{
throw new Exception($"Unhandled {nameof(NativeLeakDetectionMode)}");
}
}
NativeLeakDetection.Mode = value;
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7a96926915a7746789220056d7c409a5
timeCreated: 1507328300
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
{
"name": "Unity.Collections.Editor",
"references": [
"Unity.Collections"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"versionDefines":
[
{
"name": "Unity",
"expression": "2022.2.14f1",
"define": "UNITY_2022_2_14F1_OR_NEWER"
}
]
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c668b7a00ffe56a498ddb1fc9f96f4e6
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6353acf8df7d746d98d65f640d39ea47
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
This adds a simple ILSupport extension that adds `ref T AsRef<T>(in T thing)` to
convert a read-only (in) ref to a regular ref, to avoid defensive copies when calling
(non-mutating) methods on it. This is wrapped in UnsafeUtilityEx, as only Unity.Collections
has InternalsVisibleTo into this library.
Collections.LowLevel.ILSupport can and should be generated by codegen & ilpostprocessors,
however the ilpostproc infrastructure is unstable. Given that the result of this is
constant, we just check in the final DLL. The source for everything is in the source~
dir.
To rebuild or to add any functionality:
- delete the prebuilt DLLs in this directory
- and rename the source~ dir to source (without the ~)
- fire up Unity and let it build. Everything should be successful, you're just now using the runtime-generated DLL.
- make whatever changes you need to
- make sure Unity's builds are up to date
- copy Library/ScriptAssemblies/Unity.Collections.LowLevel.ILSupport.dll into this dir
- rename source back to source~
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 11246cfa909f81542b920bd109592bf5
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: c1cfdf44d5b6d1e9aa671a48032fee86
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 01c1358bf558f42a9aa5cba53bcd9331
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,139 @@
using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Unity.CompilationPipeline.Common.ILPostProcessing;
namespace Unity.Collections.UnsafeUtility.CodeGen
{
internal class CollectionsUnsafeUtilityPostProcessor : ILPostProcessor
{
private static CollectionsUnsafeUtilityPostProcessor s_Instance;
public override ILPostProcessor GetInstance()
{
if (s_Instance == null)
s_Instance = new CollectionsUnsafeUtilityPostProcessor();
return s_Instance;
}
public override bool WillProcess(ICompiledAssembly compiledAssembly)
{
if (compiledAssembly.Name == "Unity.Collections.LowLevel.ILSupport")
return true;
return false;
}
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
{
if (!WillProcess(compiledAssembly))
return null;
var assemblyDefinition = AssemblyDefinitionFor(compiledAssembly);
TypeDefinition ilSupportType = null;
foreach (var t in assemblyDefinition.MainModule.Types)
{
if (t.FullName == "Unity.Collections.LowLevel.Unsafe.ILSupport")
{
ilSupportType = t;
break;
}
}
if (ilSupportType == null)
throw new InvalidOperationException();
InjectUtilityAddressOfIn(ilSupportType);
InjectUtilityAsRefIn(ilSupportType);
var pe = new MemoryStream();
var pdb = new MemoryStream();
var writerParameters = new WriterParameters
{
SymbolWriterProvider = new PortablePdbWriterProvider(), SymbolStream = pdb, WriteSymbols = true
};
assemblyDefinition.Write(pe, writerParameters);
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()));
}
private void InjectUtilityAddressOfIn(TypeDefinition ctx)
{
MethodDefinition method = null;
foreach (var m in ctx.Methods)
{
if (m.Parameters[0].IsIn && m.Name.Equals("AddressOf"))
{
method = m;
break;
}
}
var il = GetILProcessorForMethod(method);
il.Append(il.Create(OpCodes.Ldarg_0));
il.Append(il.Create(OpCodes.Ret));
}
private void InjectUtilityAsRefIn(TypeDefinition ctx)
{
MethodDefinition method = null;
foreach (var m in ctx.Methods)
{
if (m.Parameters[0].IsIn && m.Name.Equals("AsRef"))
{
method = m;
break;
}
}
var il = GetILProcessorForMethod(method);
il.Append(il.Create(OpCodes.Ldarg_0));
il.Append(il.Create(OpCodes.Ret));
}
internal static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compiledAssembly)
{
var readerParameters = new ReaderParameters
{
SymbolStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PdbData),
SymbolReaderProvider = new PortablePdbReaderProvider(),
ReadingMode = ReadingMode.Immediate
};
var peStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PeData);
var assemblyDefinition = AssemblyDefinition.ReadAssembly(peStream, readerParameters);
return assemblyDefinition;
}
private static ILProcessor GetILProcessorForMethod(TypeDefinition ctx, string methodName, bool clear = true)
{
MethodDefinition method = null;
foreach (var m in ctx.Methods)
{
if (m.HasGenericParameters && m.Name.Equals(methodName))
{
method = m;
break;
}
}
return GetILProcessorForMethod(method, clear);
}
private static ILProcessor GetILProcessorForMethod(MethodDefinition method, bool clear = true)
{
var ilProcessor = method.Body.GetILProcessor();
if (clear)
{
ilProcessor.Body.Instructions.Clear();
ilProcessor.Body.Variables.Clear();
ilProcessor.Body.ExceptionHandlers.Clear();
}
return ilProcessor;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c40712b5124e4c33b9040e81f566b22
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
{
"name": "Unity.Collections.LowLevel.ILSupport.CodeGen",
"references": [
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"Mono.Cecil.dll",
"Mono.Cecil.Rocks.dll",
"Mono.Cecil.Pdb.dll"
],
"autoReferenced": false,
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 851faa33f0fe11de69f86c5599d17c88
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 38f5d8a8dc0e00d1fb83ec98cc122c85
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
using System;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.Collections")]
namespace Unity.Collections.LowLevel.Unsafe
{
internal unsafe static class ILSupport
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* AddressOf<T>(in T thing)
where T : struct
{
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T AsRef<T>(in T thing)
where T : struct
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ed138ce0eef88e8898615fee7b8acf5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
{
"name": "Unity.Collections.LowLevel.ILSupport",
"references": [
],
"includePlatforms": [
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"autoReferenced": false,
"versionDefines": [],
"noEngineReferences": true
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 231b25ba64524e26aa697960dbc7d0d0
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee3c6001d6f4bbf409631328fb4cd463
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,4 @@
using System;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.Collections.PerformanceTests")]
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1cf995a69bb0bd844b0d2a1fa5004d0b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e064d25778ff3b249a575bb25f2eaf3e
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4c3b5584c2c4c483b9816878d89d3793
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,233 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Unity.Collections.PerformanceTests
{
static class ArrayUtil
{
static public void AllocInt(ref NativeArray<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new NativeArray<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container[i] = i;
}
}
else
container.Dispose();
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Random.InitState(0);
var bclContainer = new int[capacity];
if (addValues)
{
for (int i = 0; i < capacity; i++)
bclContainer[i] = i;
}
return bclContainer;
}
static public void CreateRandomValues(int capacity, ref UnsafeList<int> values)
{
if (capacity >= 0)
{
values = new UnsafeList<int>(capacity, Allocator.Persistent);
Random.InitState(0);
for (int i = 0; i < capacity; i++)
{
int randKey = Random.Range(0, capacity);
values.Add(randKey);
}
}
else
values.Dispose();
}
}
struct ArrayLength100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeArray<int> nativeContainer;
public void AllocNativeContainer(int capacity) => ArrayUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity) => ArrayUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Length;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer() { }
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (int[])container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Length;
}
}
struct ArrayIndexedRead : IBenchmarkContainer
{
NativeArray<int> nativeContainer;
UnsafeList<int> values;
public void AllocNativeContainer(int capacity)
{
ArrayUtil.AllocInt(ref nativeContainer, capacity, true);
ArrayUtil.CreateRandomValues(capacity, ref values);
}
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity)
{
object container = ArrayUtil.AllocBclContainer(capacity, true);
ArrayUtil.CreateRandomValues(capacity, ref values);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
int insertions = values.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, reader[values[i]]);
}
public void MeasureUnsafeContainer() { }
public void MeasureBclContainer(object container)
{
var bclContainer = (int[])container;
int insertions = values.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, bclContainer[values[i]]);
}
}
struct ArrayIndexedWrite : IBenchmarkContainer
{
NativeArray<int> nativeContainer;
UnsafeList<int> values;
public void AllocNativeContainer(int capacity)
{
ArrayUtil.AllocInt(ref nativeContainer, capacity, true);
ArrayUtil.CreateRandomValues(capacity, ref values);
}
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity)
{
object container = ArrayUtil.AllocBclContainer(capacity, true);
ArrayUtil.CreateRandomValues(capacity, ref values);
return container;
}
public void MeasureNativeContainer()
{
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
nativeContainer[values[i]] = i;
}
public void MeasureUnsafeContainer() { }
public void MeasureBclContainer(object container)
{
var bclContainer = (int[])container;
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
bclContainer[values[i]] = i;
}
}
struct ArrayForEach : IBenchmarkContainer
{
NativeArray<int> nativeContainer;
public int total;
public void AllocNativeContainer(int capacity) => ArrayUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity) => ArrayUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
int value = 0;
foreach (var element in nativeContainer)
Volatile.Write(ref value, element);
}
public void MeasureUnsafeContainer() { }
public void MeasureBclContainer(object container)
{
int value = 0;
var bclContainer = (int[])container;
foreach (var element in bclContainer)
Volatile.Write(ref value, element);
}
}
[Benchmark(typeof(BenchmarkContainerType), true)]
class Array
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(Array))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(Array));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void Length_x_100k(
[Values(0, 100)] int capacity,
[Values(BenchmarkContainerType.Native, BenchmarkContainerType.NativeBurstSafety,
BenchmarkContainerType.NativeBurstNoSafety)] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ArrayLength100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedRead(
[Values(10000, 100000, 1000000)] int insertions,
[Values(BenchmarkContainerType.Native, BenchmarkContainerType.NativeBurstSafety,
BenchmarkContainerType.NativeBurstNoSafety)] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ArrayIndexedRead>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedWrite(
[Values(10000, 100000, 1000000)] int insertions,
[Values(BenchmarkContainerType.Native, BenchmarkContainerType.NativeBurstSafety,
BenchmarkContainerType.NativeBurstNoSafety)] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ArrayIndexedWrite>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(10000, 100000, 1000000)] int insertions,
[Values(BenchmarkContainerType.Native, BenchmarkContainerType.NativeBurstSafety,
BenchmarkContainerType.NativeBurstNoSafety)] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ArrayForEach>.Run(insertions, type);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c78535bf9ed19874e83db37c738974ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,399 @@
using System;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using Unity.Burst;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
namespace Unity.Collections.PerformanceTests
{
/// <summary>
/// Specifies a class containing performance test methods which should be included in allocator benchmarking.<para />
/// The values specified in this enum are unlikely to be needed in user code, but user code will specify the enum type
/// in a couple places:<para />
/// <c>[Benchmark(typeof(BenchmarkAllocatorType))] // &lt;---- HERE<br />
/// class FooAllocatorPerformanceTestMethods</c><para />
/// and<para />
/// <c>[Test, Performance]<br />
/// public unsafe void AllocatorPerfTestExample(<br />
/// [Values(1, 2, 4, 8)] int workerThreads,<br />
/// [Values(1024, 1024 * 1024)] int allocSize,<br />
/// [Values] BenchmarkAllocatorType type) // &lt;---- HERE<br />
/// {</c><para />
/// Though values may be specified in the performance test method parameter, it is recommended to leave the argument implicitly
/// covering all enum values as seen in the example above.
/// </summary>
[BenchmarkComparison(BenchmarkAllocatorConfig.Persistent, "Persistent (E)")]
[BenchmarkComparisonExternal(BenchmarkAllocatorConfig.TempJob, "TempJob (E)")]
[BenchmarkComparisonExternal(BenchmarkAllocatorConfig.Temp, "Temp (E)")]
[BenchmarkComparisonDisplay(SampleUnit.Microsecond, 1, BenchmarkAllocatorConfig.kRankingStat)]
public enum BenchmarkAllocatorType : int
{
/// <summary>Allocator performance test will execute on a managed (not burst compiled) code path</summary>
[BenchmarkName("{0} (S)")] Managed,
/// <summary>Allocator performance test will execute on a burst compile code path, with safety checks enabled</summary>
[BenchmarkName("{0} (S+B)")] BurstSafety,
/// <summary>Allocator performance test will execute on a burst compile code path, with safety checks disabled</summary>
[BenchmarkName("{0} (B)")] BurstNoSafety,
}
internal static class BenchmarkAllocatorConfig
{
internal const int Temp = -1;
internal const int TempJob = -2;
internal const int Persistent = -3;
internal const BenchmarkRankingStatistic kRankingStat = BenchmarkRankingStatistic.Min;
internal const int kCountWarmup = 5;
internal const int kCountMeasure = 50;
#if UNITY_STANDALONE || UNITY_EDITOR
internal const int kCountAllocations = 150;
#else
// Still allows allocator tests on non-desktop platforms, but with a much lower memory requirement
internal const int kCountAllocations = 25;
#endif
#if UNITY_EDITOR
[UnityEditor.MenuItem("DOTS/Unity.Collections/Generate Allocator Benchmarks")]
#endif
static void RunBenchmarks()
{
BenchmarkGenerator.GenerateMarkdown(
"Allocators",
typeof(BenchmarkAllocatorType),
"../../Packages/com.unity.collections/Documentation~/performance-comparison-allocators.md",
$"The following benchmarks make **{kCountAllocations} consecutive allocations** per sample set."
+ $"<br/>Multithreaded benchmarks make the full **{kCountAllocations} consecutive allocations *per worker thread*** per sample set."
+ $"<br/>The **{kRankingStat} of {kCountMeasure} sample sets** is compared against the baseline on the far right side of the table."
+ $"<br/>{kCountWarmup} extra sample sets are run as warmup."
,
"Legend",
new string[]
{
"`(S)` = Safety Enabled",
"`(B)` = Burst Compiled *with Safety Disabled*",
"`(S+B)` = Burst Compiled *with Safety Enabled*",
"`(E)` = Engine Provided",
"",
"*`italic`* results are for benchmarking comparison only; these are not included in standard Performance Framework tests",
});
}
}
/// <summary>
/// Interface to implement allocator performance tests which will run using <see cref="BenchmarkAllocatorRunner{T}.Run(BenchmarkAllocatorType, int, int, int[])"/>.
/// Deriving tests from this interface enables both Performance Test Framework and Benchmark Framework to generate and run
/// tests for the contexts described by <see cref="BenchmarkAllocatorType"/>.
/// </summary>
public interface IBenchmarkAllocator
{
/// <summary>
/// Override this to add extra int arguments to a performance test implementation as fields in the implementing type. These arguments
/// are optionally passed in through <see cref="BenchmarkAllocatorRunner{T}.Run(BenchmarkAllocatorType, int, int, int[])"/>.
/// </summary>
/// <param name="args">A variable number of extra arguments to passed through to the test implementation</param>
public void SetParams(params int[] args) { }
/// <summary>
/// Used to create the allocator used in performance testing.
/// </summary>
/// <param name="builtinOverride">When this is <see cref="Allocator.None"/>, create the custom allocator type.
/// Otherwise use the provided <see cref="Allocator"/> enum for allocations in performance testing.</param>
public void CreateAllocator(Allocator builtinOverride);
/// <summary>
/// Used to free memory and destroy the custom allocator if it wasn't allocated with an <see cref="Allocator"/> type.
/// </summary>
public void DestroyAllocator();
/// <summary>
/// Actions performed prior to each measurement of a sample set. Typically used to set up initial state to ensure each sample measured is executed in the same way.
/// </summary>
/// <param name="workers">Number of job workers for this allocation test. Work is duplicated across job workers rather than split across job workers.</param>
/// <param name="size">The base size of each allocation in a single measurement.</param>
/// <param name="allocations">The number of allocations in a single measurement.</param>
public void Setup(int workers, int size, int allocations);
/// <summary>
/// Actions performed following each measurement of a sample set. Typically used to dispose or invalidate the state set up during <see cref="Setup(int, int, int)"/>.
/// </summary>
public void Teardown();
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to work with any allocator, so if making
/// allocations or freeing, the recommendation is to interface through <see cref="AllocatorManager"/>.
/// </summary>
/// <param name="workerI"></param>
public void Measure(int workerI);
}
/// <summary>
/// Provides the API for running allocator based Performance Framework tests and Benchmark Framework measurements.
/// This will typically be the sole call from a performance test. See <see cref="Run(BenchmarkAllocatorType, int, int, int[])"/>
/// for more information.
/// </summary>
/// <typeparam name="T">An implementation conforming to the <see cref="IBenchmarkAllocator"/> interface for running allocator performance tests and benchmarks.</typeparam>
[BurstCompile(CompileSynchronously = true)]
public static class BenchmarkAllocatorRunner<T> where T : unmanaged, IBenchmarkAllocator
{
internal unsafe struct JobST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->Measure(0);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
internal unsafe struct JobBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->Measure(0);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
internal unsafe struct JobSafetyBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->Measure(0);
}
internal unsafe struct JobMT : IJobParallelFor
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->Measure(index);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
internal unsafe struct JobBurstMT : IJobParallelFor
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->Measure(index);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
internal unsafe struct JobSafetyBurstMT : IJobParallelFor
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->Measure(index);
}
static unsafe void RunST(BenchmarkAllocatorType type, int baseSize, int allocations, params int[] args)
{
var methods = new T();
methods.SetParams(args);
switch (type)
{
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.Temp):
methods.CreateAllocator(Allocator.Temp);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule().Complete(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.TempJob):
methods.CreateAllocator(Allocator.TempJob);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule().Complete(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.Persistent):
methods.CreateAllocator(Allocator.Persistent);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule().Complete(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.Managed:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule().Complete(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.BurstSafety:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobSafetyBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.BurstNoSafety:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.Measure(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.Setup(1, baseSize, allocations), () => methods.Teardown());
break;
}
methods.DestroyAllocator();
}
static unsafe void RunMT(BenchmarkAllocatorType type, int baseSize, int allocations, int workers, params int[] args)
{
var methods = new T();
methods.SetParams(args);
switch (type)
{
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.Temp):
methods.CreateAllocator(Allocator.Temp);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.TempJob):
methods.CreateAllocator(Allocator.TempJob);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
case (BenchmarkAllocatorType)(BenchmarkAllocatorConfig.Persistent):
methods.CreateAllocator(Allocator.Persistent);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.Managed:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.BurstSafety:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobSafetyBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
case BenchmarkAllocatorType.BurstNoSafety:
methods.CreateAllocator(Allocator.None);
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkAllocatorConfig.kCountWarmup, BenchmarkAllocatorConfig.kCountMeasure,
() => new JobBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.Setup(workers, baseSize, allocations), () => methods.Teardown());
break;
}
methods.DestroyAllocator();
}
/// <summary>
/// Called from a typical performance test method to provide both Performance Framework measurements as well as
/// Benchmark Framework measurements. A typical usage is similar to:
/// <c>[Test, Performance]<br />
/// [Category("Performance")]<br />
/// [BenchmarkTestFootnote]<br />
/// public unsafe void FixedSize(<br />
/// [Values(1, 2, 4, 8)] int workerThreads,<br />
/// [Values(1024, 1024 * 1024)] int allocSize,<br />
/// [Values] BenchmarkAllocatorType type)<br />
/// {<br />
/// BenchmarkAllocatorRunner&lt;Rewindable_FixedSize&gt;.Run(type, allocSize, workerThreads);<br />
/// }</c>
/// </summary>
/// <param name="type">The benchmark or performance measurement type to run for allocators i.e. <see cref="BenchmarkAllocatorType.Managed"/> etc.</param>
/// <param name="baseSize">The size to base allocations off of, whether fixed for all allocations, increasing in size, or anything else.</param>
/// <param name="workers">The number of job workers to run performance tests on. These are duplicated across workers rather than split across workers.</param>
/// <param name="args">Optional arguments that can be stored in a test implementation class.</param>
public static unsafe void Run(BenchmarkAllocatorType type, int baseSize, int workers, params int[] args)
{
if (workers == 1)
RunST(type, baseSize, BenchmarkAllocatorConfig.kCountAllocations, args);
else
RunMT(type, baseSize, BenchmarkAllocatorConfig.kCountAllocations, workers, args);
}
}
/// <summary>
/// A useful set of functionality commonly found in allocator performance and benchmark tests for most allocator types. Typically
/// wrapped in a separate utility class for a set of tests to a specific allocator type.
/// </summary>
public struct BenchmarkAllocatorUtil
{
/// <summary>
/// [worker][sequential allocation]<para />
/// Used to store the pointer from allocations so it may be freed later.
/// </summary>
public NativeArray<NativeArray<IntPtr>> AllocPtr { get; private set; }
/// <summary>
/// [sequential allocation]<para />
/// Used to store the size of allocations so it may be freed later, as some allocators require the size to be explicitly given when freed.
/// Separate arrays for each worker are not provided because workers duplicate the same work rather than splitting it in some manner.
/// </summary>
public NativeArray<int> AllocSize { get; private set; }
/// <summary>
/// To be called prior to each measurement. Sets up the allocation and size storage used for freeing allocations, whether this happens
/// during teardown following each measurement, or freeing is the functionality being measured itself.
/// </summary>
/// <param name="workers">The number of job workers to run performance tests on. These are duplicated across workers rather than split across workers.</param>
/// <param name="baseSize">The size to base allocations off of, whether fixed for all allocations, increasing in size, or anything else.</param>
/// <param name="growthRate">
/// - If &lt; 0, a performance measurement's allocations start at the largest size and decrease linearly to the `baseSize`.
/// - If &gt; 0, a performance measurement's allocations start at the `baseSize` and increase linearly
/// - If 0, the allocation size is equivalent to the `baseSize` for all of a performance measurement's allocations
/// </param>
/// <param name="allocations">The number of allocations in a single measurement.</param>
public void Setup(int workers, int baseSize, int growthRate, int allocations)
{
var allocStorage = new NativeArray<NativeArray<IntPtr>>(workers, Allocator.Persistent);
for (int i = 0; i < workers; i++)
allocStorage[i] = new NativeArray<IntPtr>(allocations, Allocator.Persistent);
AllocPtr = allocStorage;
var sizeStorage = new NativeArray<int>(allocations, Allocator.Persistent);
for (int i = 0; i < allocations; i++)
{
if (growthRate >= 0)
sizeStorage[i] = baseSize + growthRate * i;
else
sizeStorage[i] = baseSize + (-growthRate * (allocations - 1)) + growthRate * i;
}
AllocSize = sizeStorage;
}
/// <summary>
/// To be called following each measurement. Frees the memory allocated in the <see cref="Setup(int, int, int, int)"/> method.
/// This also frees the memory allocated by the given allocator using the stored information in this class.
/// </summary>
/// <param name="allocator">A handle to the allocator being measured.</param>
unsafe public void Teardown(AllocatorManager.AllocatorHandle allocator)
{
if (AllocPtr.IsCreated)
{
for (int i = 0; i < AllocPtr.Length; i++)
{
var inner = AllocPtr[i];
for (int j = 0; j < inner.Length; j++)
{
AllocatorManager.Free(allocator, (void*)inner[j], AllocSize[j], 0);
inner[j] = IntPtr.Zero;
}
}
}
Teardown();
}
/// <summary>
/// To be called following each measurement. Frees the memory allocated in the <see cref="Setup(int, int, int, int)"/> method.
/// This does not free the memory allocated by a given allocator type used in measurement tests.
/// </summary>
public void Teardown()
{
if (AllocPtr.IsCreated)
{
for (int i = 0; i < AllocPtr.Length; i++)
{
if (AllocPtr[i].IsCreated)
AllocPtr[i].Dispose();
}
AllocPtr.Dispose();
}
if (AllocSize.IsCreated)
AllocSize.Dispose();
}
}
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 29f92070f574cff4a948d1b4f2b88cd3
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,287 @@
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using Unity.Burst;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
namespace Unity.Collections.PerformanceTests
{
/// <summary>
/// Specifies a class containing performance test methods which should be included in container benchmarking.<para />
/// The values specified in this enum are unlikely to be needed in user code, but user code will specify the enum type
/// in a couple places:<para />
/// <c>[Benchmark(typeof(BenchmarkContainerType))] // &lt;---- HERE<br />
/// class FooContainerPerformanceTestMethods</c><para />
/// and<para />
/// <c>[Test, Performance]<br />
/// public unsafe void ContainerPerfTestExample(<br />
/// [Values(100000, 1000000, 10000000)] int capacity,<br />
/// [Values] BenchmarkContainerType type) // &lt;---- HERE<br />
/// {</c><para />
/// Though values may be specified in the performance test method parameter, it is recommended to leave the argument implicitly
/// covering all enum values as seen in the example above.
/// </summary>
[BenchmarkComparison(BenchmarkContainerConfig.BCL, "{0} (BCL)")]
[BenchmarkComparisonDisplay(SampleUnit.Millisecond, 3, BenchmarkContainerConfig.kRankingMethod)]
public enum BenchmarkContainerType : int
{
/// <summary>Native container performance test will execute on a managed (not burst compiled) code path</summary>
[BenchmarkName("Native{0} (S)")] Native,
/// <summary>Native container performance test will execute on a burst compile code path, with safety checks enabled</summary>
[BenchmarkName("Native{0} (S+B)")] NativeBurstSafety,
/// <summary>Native container performance test will execute on a burst compile code path, with safety checks disabled</summary>
[BenchmarkName("Native{0} (B)")] NativeBurstNoSafety,
/// <summary>Unsafe container performance test will execute on a managed (not burst compiled) code path</summary>
[BenchmarkName("Unsafe{0} (S)")] Unsafe,
/// <summary>Unsafe container performance test will execute on a burst compile code path, with safety checks enabled</summary>
[BenchmarkName("Unsafe{0} (S+B)")] UnsafeBurstSafety,
/// <summary>Unsafe container performance test will execute on a burst compile code path, with safety checks disabled</summary>
[BenchmarkName("Unsafe{0} (B)")] UnsafeBurstNoSafety,
}
/// <summary>
/// Configuration settings for benchmarking containers.
/// </summary>
public static class BenchmarkContainerConfig
{
/// <summary>
/// An additional value to the enum values defined in <see cref="BenchmarkContainerType"/> which will not be included
/// in Performance Test Framework test generation but will be included in Benchmark Framework result generation.
/// </summary>
public const int BCL = -1;
internal const BenchmarkRankingStatistic kRankingMethod = BenchmarkRankingStatistic.Median;
internal const int kCountWarmup = 5;
internal const int kCountMeasure = 10;
/// <summary>
/// Prefix string for individual benchmark menu items
/// </summary>
public const string kMenuItemIndividual = "DOTS/Unity.Collections/Generate Individual Container Benchmark/";
#if UNITY_EDITOR
[UnityEditor.MenuItem("DOTS/Unity.Collections/Generate Container Benchmarks")]
#endif
static void RunBenchmarks() =>
BenchmarkGenerator.GenerateMarkdown(
"Containers",
typeof(BenchmarkContainerType),
"../../Packages/com.unity.collections/Documentation~/performance-comparison-containers.md",
$"The **{kRankingMethod} of {kCountMeasure} sample sets** is compared against the baseline on the far right side of the table."
+ $"<br/>Multithreaded benchmarks divide the processing amongst the specified number of workers."
+ $"<br/>{kCountWarmup} extra sample sets are run as warmup."
,
"Legend",
new string[]
{
"`(S)` = Safety Enabled",
"`(B)` = Burst Compiled *with Safety Disabled*",
"`(S+B)` = Burst Compiled *with Safety Enabled*",
"`(BCL)` = Base Class Library implementation (such as provided by Mono or .NET)",
"",
"*`italic`* results are for benchmarking comparison only; these are not included in standard Performance Framework tests",
});
#if UNITY_EDITOR
/// <summary>
/// Runs a benchmark for a particular class with Performance Test Framework/Benchmark methods. For calling
/// from custom menu items, for instance.
/// </summary>
/// <param name="testClassType"></param>
public static void RunBenchmark(System.Type testClassType)
{
string tempPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
UnityEditor.FileUtil.GetUniqueTempPathInProject()), $"Benchmark{testClassType.Name}.md");
BenchmarkGenerator.GenerateMarkdown(
$"Individual -- {testClassType.Name}",
new System.Type[] { testClassType },
tempPath,
$"The **{kRankingMethod} of {kCountMeasure} sample sets** is compared against the baseline on the far right side of the table."
+ $"<br/>Multithreaded benchmarks divide the processing amongst the specified number of workers."
+ $"<br/>{kCountWarmup} extra sample sets are run as warmup."
,
"Legend",
new string[]
{
"`(S)` = Safety Enabled",
"`(B)` = Burst Compiled *with Safety Disabled*",
"`(S+B)` = Burst Compiled *with Safety Enabled*",
"`(BCL)` = Base Class Library implementation (such as provided by Mono or .NET)",
"",
"*`italic`* results are for benchmarking comparison only; these are not included in standard Performance Framework tests",
});
UnityEditor.EditorUtility.RevealInFinder(tempPath);
}
#endif
}
/// <summary>
/// Interface to implement container performance tests which will run using <see cref="BenchmarkContainerRunner{T}.Run(int, BenchmarkContainerType, int[])"/>.
/// Deriving tests from this interface enables both Performance Test Framework and Benchmark Framework to generate and run
/// tests for the contexts described by <see cref="BenchmarkContainerType"/>.
/// </summary>
public interface IBenchmarkContainer
{
/// <summary>
/// Override this to add extra int arguments to a performance test implementation as fields in the implementing type. These arguments
/// are optionally passed in through <see cref="BenchmarkContainerRunner{T}.Run(int, BenchmarkContainerType, int[])"/>.
/// </summary>
/// <param name="capacity">The initial capacity to requested for the container.</param>
/// <param name="args">A variable number of extra arguments to passed through to the test implementation</param>
public void SetParams(int capacity, params int[] args) { }
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the native container
/// when the benchmark type is <see cref="BenchmarkContainerType.Native"/>, <see cref="BenchmarkContainerType.NativeBurstNoSafety"/>,
/// or <see cref="BenchmarkContainerType.NativeBurstSafety"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
public void AllocNativeContainer(int capacity);
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the unsafe container
/// when the benchmark type is <see cref="BenchmarkContainerType.Unsafe"/>, <see cref="BenchmarkContainerType.UnsafeBurstNoSafety"/>,
/// or <see cref="BenchmarkContainerType.UnsafeBurstSafety"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
public void AllocUnsafeContainer(int capacity); // capacity 0 frees
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the managed container
/// when the benchmark type is <see cref="BenchmarkContainerConfig.BCL"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
/// <returns>A reference to the allocated container when capacity &gt;= 0, and `null` when capacity &lt; 0.</returns>
public object AllocBclContainer(int capacity);
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any native container.
/// </summary>
public void MeasureNativeContainer();
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any unsafe container.
/// </summary>
public void MeasureUnsafeContainer();
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any managed container provided by the Base Class Library (BCL).
/// </summary>
/// <param name="container">A reference to the managed container allocated in <see cref="AllocBclContainer(int)"/></param>
public void MeasureBclContainer(object container);
}
/// <summary>
/// Provides the API for running container based Performance Framework tests and Benchmark Framework measurements.
/// This will typically be the sole call from a performance test. See <see cref="Run(int, BenchmarkContainerType, int[])"/>
/// for more information.
/// </summary>
/// <typeparam name="T">An implementation conforming to the <see cref="IBenchmarkContainer"/> interface for running container performance tests and benchmarks.</typeparam>
[BurstCompile(CompileSynchronously = true)]
public static class BenchmarkContainerRunner<T> where T : unmanaged, IBenchmarkContainer
{
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct NativeJobBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureNativeContainer();
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct NativeJobSafetyBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureNativeContainer();
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct UnsafeJobBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureUnsafeContainer();
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct UnsafeJobSafetyBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureUnsafeContainer();
}
/// <summary>
/// Called from a typical performance test method to provide both Performance Framework measurements as well as
/// Benchmark Framework measurements. A typical usage is similar to:
/// <c>[Test, Performance]<br />
/// [Category("Performance")]<br />
/// public unsafe void ToNativeArray(<br />
/// [Values(100000, 1000000, 10000000)] int capacity,<br />
/// [Values] BenchmarkContainerType type)<br />
/// {<br />
/// BenchmarkContainerRunner&lt;HashSetToNativeArray&gt;.RunST(capacity, type);<br />
/// }</c>
/// </summary>
/// <param name="capacity">The capacity for the container(s) which will be passed to setup methods</param>
/// <param name="type">The benchmark or performance measurement type to run for containers i.e. <see cref="BenchmarkContainerType.Native"/> etc.</param>
/// <param name="args">Optional arguments that can be stored in a test implementation class.</param>
/// <remarks>This will run measurements with <see cref="IJob"/> or directly called on the main thread.</remarks>
public static unsafe void Run(int capacity, BenchmarkContainerType type, params int[] args)
{
var methods = new T();
methods.SetParams(capacity, args);
switch (type)
{
case (BenchmarkContainerType)(BenchmarkContainerConfig.BCL):
object container = null;
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureBclContainer(container),
() => container = methods.AllocBclContainer(capacity), () => container = methods.AllocBclContainer(-1));
break;
case BenchmarkContainerType.Native:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureNativeContainer(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobSafetyBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstNoSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.Unsafe:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureUnsafeContainer(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobSafetyBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstNoSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7956c264a4f322048ae516dae097b33a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,324 @@
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using Unity.Burst;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using System.Runtime.InteropServices;
namespace Unity.Collections.PerformanceTests
{
/// <summary>
/// Interface to implement container performance tests which will run using <see cref="BenchmarkContainerRunnerParallel{T}.Run))"/>.
/// Deriving tests from this interface enables both Performance Test Framework and Benchmark Framework to generate and run
/// tests for the contexts described by <see cref="BenchmarkContainerType"/>.
/// </summary>
public interface IBenchmarkContainerParallel
{
/// <summary>
/// Override this to add extra int arguments to a performance test implementation as fields in the implementing type. These arguments
/// are optionally passed in through <see cref="BenchmarkContainerRunner{T}.Run(int, BenchmarkContainerType, int[])"/>.
/// </summary>
/// <param name="capacity">The initial capacity to requested for the container.</param>
/// <param name="args">A variable number of extra arguments to passed through to the test implementation</param>
public void SetParams(int capacity, params int[] args) { }
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the native container
/// when the benchmark type is <see cref="BenchmarkContainerType.Native"/>, <see cref="BenchmarkContainerType.NativeBurstNoSafety"/>,
/// or <see cref="BenchmarkContainerType.NativeBurstSafety"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
public void AllocNativeContainer(int capacity);
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the unsafe container
/// when the benchmark type is <see cref="BenchmarkContainerType.Unsafe"/>, <see cref="BenchmarkContainerType.UnsafeBurstNoSafety"/>,
/// or <see cref="BenchmarkContainerType.UnsafeBurstSafety"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
public void AllocUnsafeContainer(int capacity);
/// <summary>
/// Called during setup for each measurement in a sample set with the capacity to allocate to the managed container
/// when the benchmark type is <see cref="BenchmarkContainerConfig.BCL"/>.<para />
/// This is also called during teardown for each measurement in a sample set with '-1' to indicate freeing the container.
/// </summary>
/// <param name="capacity">The capacity to allocate for the managed container. Capacity of 0 will still create a container,
/// but it will be empty. A capacity of -1 will dispose the container and free associated allocation(s).</param>
/// <returns>A reference to the allocated container when capacity &gt;= 0, and `null` when capacity &lt; 0.</returns>
public object AllocBclContainer(int capacity);
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any native container.
/// </summary>
/// <param name="worker">The worker index out of the number of job workers requested for parallel benchmarking</param>
/// <param name="threadIndex">The job system thread index which must be specified in some cases for a container's ParallelWriter</param>
public void MeasureNativeContainer(int worker, int threadIndex);
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any unsafe container.
/// </summary>
/// <param name="worker">The worker index out of the number of job workers requested for parallel benchmarking</param>
/// <param name="threadIndex">The job system thread index which must be specified in some cases for a container's ParallelWriter</param>
public void MeasureUnsafeContainer(int worker, int threadIndex);
/// <summary>
/// The code which will be executed during performance measurement. This should usually be general enough to
/// work with any managed container provided by the Base Class Library (BCL).
/// </summary>
/// <param name="container">A reference to the managed container allocated in <see cref="AllocBclContainer(int)"/></param>
/// <param name="worker">The worker index out of the number of job workers requested for parallel benchmarking</param>
public void MeasureBclContainer(object container, int worker);
}
/// <summary>
/// Provides the API for running container based Performance Framework tests and Benchmark Framework measurements.
/// This will typically be the sole call from a performance test. See <see cref="Run(int, BenchmarkContainerType, int[])"/>
/// for more information.
/// </summary>
/// <typeparam name="T">An implementation conforming to the <see cref="IBenchmarkContainer"/> interface for running container performance tests and benchmarks.</typeparam>
[BurstCompile(CompileSynchronously = true)]
public static class BenchmarkContainerRunnerParallel<T> where T : unmanaged, IBenchmarkContainerParallel
{
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct NativeJobBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureNativeContainer(0, 0);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct NativeJobSafetyBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureNativeContainer(0, 0);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct UnsafeJobBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureUnsafeContainer(0, 0);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct UnsafeJobSafetyBurstST : IJob
{
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute() => methods->MeasureUnsafeContainer(0, 0);
}
unsafe struct NativeJobMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureNativeContainer(index, threadIndex);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct NativeJobBurstMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureNativeContainer(index, threadIndex);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct NativeJobSafetyBurstMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureNativeContainer(index, threadIndex);
}
unsafe struct UnsafeJobMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureUnsafeContainer(index, threadIndex);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = true)]
unsafe struct UnsafeJobBurstMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureUnsafeContainer(index, threadIndex);
}
[BurstCompile(CompileSynchronously = true, DisableSafetyChecks = false)]
unsafe struct UnsafeJobSafetyBurstMT : IJobParallelFor
{
[NativeSetThreadIndex] int threadIndex;
[NativeDisableUnsafePtrRestriction] public T* methods;
public void Execute(int index) => methods->MeasureUnsafeContainer(index, threadIndex);
}
unsafe struct BclJobMT : IJobParallelFor
{
[NativeDisableUnsafePtrRestriction] public T* methods;
[NativeDisableUnsafePtrRestriction] public GCHandle* gcHandle;
public void Execute(int index) => methods->MeasureBclContainer(gcHandle->Target, index);
}
static unsafe void RunMT(int workers, int capacity, BenchmarkContainerType type, params int[] args)
{
var methods = new T();
methods.SetParams(capacity, args);
switch (type)
{
case (BenchmarkContainerType)(BenchmarkContainerConfig.BCL):
object container = null;
GCHandle* gcHandle = default;
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new BclJobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods), gcHandle = gcHandle }.Schedule(workers, 1).Complete(),
() =>
{
container = methods.AllocBclContainer(capacity);
gcHandle = (GCHandle*)UnsafeUtility.Malloc(sizeof(GCHandle), 0, Allocator.Persistent);
*gcHandle = GCHandle.Alloc(container);
},
() =>
{
gcHandle->Free();
UnsafeUtility.Free(gcHandle, Allocator.Persistent);
container = methods.AllocBclContainer(-1);
});
break;
case BenchmarkContainerType.Native:
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstSafety:
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobSafetyBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstNoSafety:
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.Unsafe:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobSafetyBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstNoSafety:
BenchmarkMeasure.MeasureParallel(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobBurstMT { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Schedule(workers, 1).Complete(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
}
}
/// <summary>
/// Called from a typical performance test method to provide both Performance Framework measurements as well as
/// Benchmark Framework measurements. A typical usage is similar to:
/// <c>[Test, Performance]<br />
/// [Category("Performance")]<br />
/// public unsafe void ToNativeArray(<br />
/// [Values(100000, 1000000, 10000000)] int capacity,<br />
/// [Values] BenchmarkContainerType type)<br />
/// {<br />
/// BenchmarkContainerRunner&lt;HashSetToNativeArray&gt;.RunST(capacity, type);<br />
/// }</c>
/// </summary>
/// <param name="capacity">The capacity for the container(s) which will be passed to setup methods</param>
/// <param name="type">The benchmark or performance measurement type to run for containers i.e. <see cref="BenchmarkContainerType.Native"/> etc.</param>
/// <param name="args">Optional arguments that can be stored in a test implementation class.</param>
/// <remarks>This will run measurements with <see cref="IJob"/> or directly called on the main thread.</remarks>
public static unsafe void Run(int capacity, BenchmarkContainerType type, params int[] args)
{
var methods = new T();
methods.SetParams(capacity, args);
switch (type)
{
case (BenchmarkContainerType)(BenchmarkContainerConfig.BCL):
object container = null;
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureBclContainer(container, 0),
() => container = methods.AllocBclContainer(capacity), () => container = methods.AllocBclContainer(-1));
break;
case BenchmarkContainerType.Native:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureNativeContainer(0, 0),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobSafetyBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.NativeBurstNoSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new NativeJobBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocNativeContainer(capacity), () => methods.AllocNativeContainer(-1));
break;
case BenchmarkContainerType.Unsafe:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => methods.MeasureUnsafeContainer(0, 0),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobSafetyBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
case BenchmarkContainerType.UnsafeBurstNoSafety:
BenchmarkMeasure.Measure(typeof(T),
BenchmarkContainerConfig.kCountWarmup, BenchmarkContainerConfig.kCountMeasure,
() => new UnsafeJobBurstST { methods = (T*)UnsafeUtility.AddressOf(ref methods) }.Run(),
() => methods.AllocUnsafeContainer(capacity), () => methods.AllocUnsafeContainer(-1));
break;
}
}
/// <summary>
/// Called from a typical performance test method to provide both Performance Framework measurements as well as
/// Benchmark Framework measurements. A typical usage is similar to:
/// <c>[Test, Performance]<br />
/// [Category("Performance")]<br />
/// public unsafe void ToNativeArray(<br />
/// [Values(1, 2, 4, 8)] int workers,<br />
/// [Values(100000, 1000000, 10000000)] int capacity,<br />
/// [Values] BenchmarkContainerType type)<br />
/// {<br />
/// BenchmarkContainerRunner&lt;HashSetToNativeArray&gt;.Run(workers, capacity, type);<br />
/// }</c>
/// </summary>
/// <param name="workers">The number of job workers to run performance tests on. These are duplicated across workers rather than split across workers.</param>
/// <param name="capacity">The capacity for the container(s) which will be passed to setup methods</param>
/// <param name="type">The benchmark or performance measurement type to run for containers i.e. <see cref="BenchmarkContainerType.Native"/> etc.</param>
/// <param name="args">Optional arguments that can be stored in a test implementation class.</param>
/// <remarks>This will run measurements with <see cref="IJob"/> or <see cref="IJobParallelFor"/> based on the number of workers being 1 or 2+, respectively.</remarks>
public static unsafe void Run(int workers, int capacity, BenchmarkContainerType type, params int[] args)
{
if (workers == 1)
Run(capacity, type, args);
else
RunMT(workers, capacity, type, args);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eec34f52a2dc6704f938be2c9ab97954
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,872 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
using Unity.Mathematics;
using UnityEditor;
using Random = Unity.Mathematics.Random;
namespace Unity.Collections.PerformanceTests
{
static class HashMapUtil
{
internal const uint K_RANDOM_SEED_1 = 2210602657;
internal const uint K_RANDOM_SEED_2 = 2210602658;
internal const uint K_RANDOM_SEED_3 = 2210602659;
static public void AllocInt(ref NativeHashMap<int, int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_1);
container = new NativeHashMap<int, int>(capacity, Allocator.Persistent);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (container.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
}
else
container.Dispose();
}
static public void AllocInt(ref UnsafeHashMap<int, int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_1);
container = new UnsafeHashMap<int, int>(capacity, Allocator.Persistent);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (container.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
}
else
container.Dispose();
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_1);
var bclContainer = new System.Collections.Generic.Dictionary<int, int>(capacity);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (bclContainer.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
return bclContainer;
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref UnsafeHashMap<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey) && !hashMap.ContainsKey(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref System.Collections.Generic.Dictionary<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey) && !hashMap.ContainsKey(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref NativeHashMap<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey) && !hashMap.ContainsKey(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void RandomlyShuffleKeys(int capacity, ref UnsafeList<int> keys)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Mathematics.Random(K_RANDOM_SEED_3);
for (int i = 0; i < capacity; i++)
{
int keyAt = keys[i];
int randomIndex = random.NextInt(0, capacity - 1);
keys[i] = keys[randomIndex];
keys[randomIndex] = keyAt;
}
}
}
}
struct HashMapIsEmpty100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashMapUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count == 0;
}
}
struct HashMapCount100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashMapUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Count;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Count;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count;
}
}
struct HashMapToNativeArrayKeys : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
var asArray = nativeContainer.GetKeyArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer()
{
var asArray = unsafeContainer.GetKeyArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.Keys.CopyTo(asArray, 0);
}
}
struct HashMapToNativeArrayValues : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
var asArray = nativeContainer.GetValueArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer()
{
var asArray = unsafeContainer.GetValueArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.Values.CopyTo(asArray, 0);
}
}
struct HashMapInsert : IBenchmarkContainer
{
int capacity;
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys, ref nativeContainer);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys, ref unsafeContainer);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys, ref bclContainer);
return container;
}
public void MeasureNativeContainer()
{
for (int i = 0; i < capacity; i++)
nativeContainer.Add(keys[i], i);
}
public void MeasureUnsafeContainer()
{
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(keys[i], i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
for (int i = 0; i < capacity; i++)
bclContainer.Add(keys[i], i);
}
}
struct HashMapAddGrow : IBenchmarkContainer
{
int capacity;
int toAdd;
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainer.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
toAdd = args[0];
}
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
int toAddCount = capacity < 0 ? -1 : toAdd;
HashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref nativeContainer);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
int toAddCount = capacity < 0 ? -1 : toAdd;
HashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref unsafeContainer);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, true);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int toAddCount = capacity < 0 ? -1 : toAdd;
HashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref bclContainer);
return container;
}
public void MeasureNativeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
nativeContainer.Add(keys[i], i);
}
public void MeasureUnsafeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
unsafeContainer.Add(keys[i], i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
bclContainer.Add(keys[i], i);
}
}
struct HashMapContains : IBenchmarkContainer
{
int capacity;
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.ContainsKey(keys[i]));
}
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.ContainsKey(keys[i]));
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, bclContainer.ContainsKey(keys[i]));
}
}
struct HashMapIndexedRead : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, reader[keys[i]]);
}
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, reader[keys[i]]);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, bclContainer[keys[i]]);
}
}
struct HashMapIndexedWrite : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
var container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer[keys[i]] = i;
}
public void MeasureUnsafeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer[keys[i]] = i;
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer[keys[i]] = i;
}
}
struct HashMapTryGetValue : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
{
reader.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
{
reader.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
{
bclContainer.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
}
struct HashMapRemove : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
HashMapUtil.AllocInt(ref nativeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
HashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = HashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
HashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
HashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer.Remove(keys[i]);
}
public void MeasureUnsafeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer.Remove(keys[i]);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer.Remove(keys[i]);
}
}
struct HashMapForEach : IBenchmarkContainer
{
NativeHashMap<int, int> nativeContainer;
UnsafeHashMap<int, int> unsafeContainer;
public int total;
public void AllocNativeContainer(int capacity) => HashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
foreach (var pair in nativeContainer)
Volatile.Read(ref pair.Value);
}
public void MeasureUnsafeContainer()
{
foreach (var pair in unsafeContainer)
Volatile.Read(ref pair.Value);
}
public void MeasureBclContainer(object container)
{
int value = 0;
var bclContainer = (System.Collections.Generic.Dictionary<int, int>)container;
foreach (var pair in bclContainer)
Volatile.Write(ref value, pair.Value);
}
}
[Benchmark(typeof(BenchmarkContainerType))]
[BenchmarkNameOverride(BenchmarkContainerConfig.BCL, "Dictionary")]
class HashMap
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(HashMap))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(HashMap));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void IsEmpty_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapIsEmpty100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Count_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapCount100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArrayKeys(
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapToNativeArrayKeys>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArrayValues(
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapToNativeArrayValues>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Insert(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapInsert>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
[BenchmarkTestFootnote("Incrementally grows from `capacity` until reaching size of `growTo`")]
public unsafe void AddGrow(
[Values(4, 65536)] int capacity,
[Values(1024 * 1024)] int growTo,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapAddGrow>.Run(capacity, type, growTo);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Contains(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapContains>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedRead(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapIndexedRead>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedWrite(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapIndexedWrite>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void TryGetValue(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapTryGetValue>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Remove(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapRemove>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashMapForEach>.Run(insertions, type);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41c0417bb1f33184482fea43a7d2b5c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,588 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Collections.Generic;
namespace Unity.Collections.PerformanceTests
{
static class HashSetUtil
{
static public void AllocInt(ref NativeHashSet<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new NativeHashSet<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public void AllocInt(ref NativeHashSet<int> containerA, ref NativeHashSet<int> containerB, int capacity, bool addValues)
{
AllocInt(ref containerA, capacity, false);
AllocInt(ref containerB, capacity, false);
if (!addValues)
return;
for (int i = 0; i < capacity; i++)
{
containerA.Add(Random.Range(0, capacity * 2));
containerB.Add(Random.Range(0, capacity * 2));
}
}
static public void AllocInt(ref UnsafeHashSet<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new UnsafeHashSet<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public void AllocInt(ref UnsafeHashSet<int> containerA, ref UnsafeHashSet<int> containerB, int capacity, bool addValues)
{
AllocInt(ref containerA, capacity, false);
AllocInt(ref containerB, capacity, false);
if (!addValues)
return;
for (int i = 0; i < capacity; i++)
{
containerA.Add(Random.Range(0, capacity * 2));
containerB.Add(Random.Range(0, capacity * 2));
}
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Random.InitState(0);
var bclContainer = new HashSet<int>(capacity);
if (addValues)
{
for (int i = 0; i < capacity; i++)
bclContainer.Add(i);
}
return bclContainer;
}
static public object AllocBclContainerTuple(int capacity, bool addValues)
{
var tuple = new System.Tuple<HashSet<int>, HashSet<int>>(
(HashSet<int>)AllocBclContainer(capacity, false),
(HashSet<int>)AllocBclContainer(capacity, false));
if (addValues)
{
for (int i = 0; i < capacity; i++)
{
tuple.Item1.Add(Random.Range(0, capacity * 2));
tuple.Item2.Add(Random.Range(0, capacity * 2));
}
}
return tuple;
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
Random.InitState(0);
for (int i = 0; i < capacity; i++)
{
int randKey = Random.Range(0, capacity);
keys.Add(randKey);
}
}
else
keys.Dispose();
}
}
struct HashSetIsEmpty100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count == 0;
}
}
struct HashSetCount100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Count;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Count;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count;
}
}
struct HashSetToNativeArray : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
var asArray = nativeContainer.ToNativeArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer()
{
var asArray = unsafeContainer.ToNativeArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.CopyTo(asArray, 0);
}
}
struct HashSetInsert : IBenchmarkContainer
{
int capacity;
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, false);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, false);
public void MeasureNativeContainer()
{
for (int i = 0; i < capacity; i++)
nativeContainer.Add(i);
}
public void MeasureUnsafeContainer()
{
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
for (int i = 0; i < capacity; i++)
bclContainer.Add(i);
}
}
struct HashSetAddGrow : IBenchmarkContainer
{
int capacity;
int toAdd;
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
void IBenchmarkContainer.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
toAdd = args[0];
}
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
nativeContainer.Add(i);
}
public void MeasureUnsafeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
unsafeContainer.Add(i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
bclContainer.Add(i);
}
}
struct HashSetContains : IBenchmarkContainer
{
int capacity;
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity)
{
HashSetUtil.AllocInt(ref nativeContainer, capacity, false);
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.Add(keys[i]);
}
public void AllocUnsafeContainer(int capacity)
{
HashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(keys[i]);
}
public object AllocBclContainer(int capacity)
{
object container = HashSetUtil.AllocBclContainer(capacity, false);
var bclContainer = (HashSet<int>)container;
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.Add(keys[i]);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.Contains(keys[i]));
}
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.Contains(keys[i]));
}
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, bclContainer.Contains(keys[i]));
}
}
struct HashSetRemove : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
HashSetUtil.AllocInt(ref nativeContainer, capacity, false);
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.Add(keys[i]);
}
public void AllocUnsafeContainer(int capacity)
{
HashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(keys[i]);
}
public object AllocBclContainer(int capacity)
{
object container = HashSetUtil.AllocBclContainer(capacity, false);
var bclContainer = (HashSet<int>)container;
HashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.Add(keys[i]);
return container;
}
public void MeasureNativeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer.Remove(keys[i]);
}
public void MeasureUnsafeContainer()
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer.Remove(keys[i]);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (HashSet<int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer.Remove(keys[i]);
}
}
struct HashSetForEach : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
UnsafeHashSet<int> unsafeContainer;
public int total;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
int keep = 0;
foreach (var value in nativeContainer)
Volatile.Write(ref keep, value);
}
public void MeasureUnsafeContainer()
{
int keep = 0;
foreach (var value in unsafeContainer)
Volatile.Write(ref keep, value);
}
public void MeasureBclContainer(object container)
{
int keep = 0;
var bclContainer = (HashSet<int>)container;
foreach (var value in bclContainer)
Volatile.Write(ref keep, value);
}
}
struct HashSetUnionWith : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
NativeHashSet<int> nativeContainerOther;
UnsafeHashSet<int> unsafeContainer;
UnsafeHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer() => nativeContainer.UnionWith(nativeContainerOther);
public void MeasureUnsafeContainer() => unsafeContainer.UnionWith(unsafeContainerOther);
public void MeasureBclContainer(object container)
{
var dotnetContainer = (System.Tuple<HashSet<int>, HashSet<int>>)container;
dotnetContainer.Item1.UnionWith(dotnetContainer.Item2);
}
}
struct HashSetIntersectWith : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
NativeHashSet<int> nativeContainerOther;
UnsafeHashSet<int> unsafeContainer;
UnsafeHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer() => nativeContainer.IntersectWith(nativeContainerOther);
public void MeasureUnsafeContainer() => unsafeContainer.IntersectWith(unsafeContainerOther);
public void MeasureBclContainer(object container)
{
var dotnetContainer = (System.Tuple<HashSet<int>, HashSet<int>>)container;
dotnetContainer.Item1.IntersectWith(dotnetContainer.Item2);
}
}
struct HashSetExceptWith : IBenchmarkContainer
{
NativeHashSet<int> nativeContainer;
NativeHashSet<int> nativeContainerOther;
UnsafeHashSet<int> unsafeContainer;
UnsafeHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => HashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => HashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => HashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer() => nativeContainer.ExceptWith(nativeContainerOther);
public void MeasureUnsafeContainer() => unsafeContainer.ExceptWith(unsafeContainerOther);
public void MeasureBclContainer(object container)
{
var dotnetContainer = (System.Tuple<HashSet<int>, HashSet<int>>)container;
dotnetContainer.Item1.ExceptWith(dotnetContainer.Item2);
}
}
[Benchmark(typeof(BenchmarkContainerType))]
class HashSet
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(HashSet))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(HashSet));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void IsEmpty_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetIsEmpty100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Count_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetCount100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArray(
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetToNativeArray>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Insert(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetInsert>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
[BenchmarkTestFootnote("Incrementally grows from `capacity` until reaching size of `growTo`")]
public unsafe void AddGrow(
[Values(4, 65536)] int capacity,
[Values(1024 * 1024)] int growTo,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetAddGrow>.Run(capacity, type, growTo);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Contains(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetContains>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Remove(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetRemove>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetForEach>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void UnionWith(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetUnionWith>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IntersectWith(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetIntersectWith>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ExceptWith(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<HashSetExceptWith>.Run(insertions, type);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89c74bfd36912244585acb77a1268da0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,570 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Unity.Collections.PerformanceTests
{
static class ListUtil
{
static public void AllocInt(ref NativeList<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new NativeList<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public void AllocInt(ref UnsafeList<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new UnsafeList<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Random.InitState(0);
var bclContainer = new System.Collections.Generic.List<int>(capacity);
if (addValues)
{
for (int i = 0; i < capacity; i++)
bclContainer.Add(i);
}
return bclContainer;
}
static public void CreateRandomValues(int capacity, ref UnsafeList<int> values)
{
if (capacity >= 0)
{
values = new UnsafeList<int>(capacity, Allocator.Persistent);
Random.InitState(0);
for (int i = 0; i < capacity; i++)
{
int randKey = Random.Range(0, capacity);
values.Add(randKey);
}
}
else
values.Dispose();
}
}
struct ListIsEmpty100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ListUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
for (int i = 0; i < kIterations; i++)
_ = nativeContainer.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
for (int i = 0; i < kIterations; i++)
_ = unsafeContainer.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count == 0;
}
}
struct ListCount100k : IBenchmarkContainer
{
const int kIterations = 100_000;
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ListUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Length;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
for (int i = 0; i < kIterations; i++)
_ = reader.Length;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
for (int i = 0; i < kIterations; i++)
_ = bclContainer.Count;
}
}
struct ListToNativeArray : IBenchmarkContainer
{
NativeList<int> nativeContainer;
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) { }
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
var asArray = nativeContainer.ToArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer() { }
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.CopyTo(asArray, 0);
}
}
struct ListAdd : IBenchmarkContainer
{
int capacity;
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, false);
public void AllocUnsafeContainer(int capacity) => ListUtil.AllocInt(ref unsafeContainer, capacity, false);
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, false);
public void MeasureNativeContainer()
{
for (int i = 0; i < capacity; i++)
nativeContainer.Add(i);
}
public void MeasureUnsafeContainer()
{
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
for (int i = 0; i < capacity; i++)
bclContainer.Add(i);
}
}
struct ListAddGrow : IBenchmarkContainer
{
int capacity;
int toAdd;
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
void IBenchmarkContainer.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
toAdd = args[0];
}
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ListUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
nativeContainer.Add(i);
}
public void MeasureUnsafeContainer()
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
unsafeContainer.Add(i);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
bclContainer.Add(i);
}
}
struct ListContains : IBenchmarkContainer
{
int capacity;
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
UnsafeList<int> values;
void IBenchmarkContainer.SetParams(int capacity, params int[] args) => this.capacity = capacity;
public void AllocNativeContainer(int capacity)
{
ListUtil.AllocInt(ref nativeContainer, capacity, false);
ListUtil.CreateRandomValues(capacity, ref values);
for (int i = 0; i < capacity; i++)
nativeContainer.Add(values[i]);
}
public void AllocUnsafeContainer(int capacity)
{
ListUtil.AllocInt(ref unsafeContainer, capacity, false);
ListUtil.CreateRandomValues(capacity, ref values);
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(values[i]);
}
public object AllocBclContainer(int capacity)
{
object container = ListUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Generic.List<int>)container;
ListUtil.CreateRandomValues(capacity, ref values);
for (int i = 0; i < capacity; i++)
bclContainer.Add(values[i]);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.Contains(values[i]));
}
public void MeasureUnsafeContainer()
{
var reader = unsafeContainer.AsReadOnly();
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, reader.Contains(values[i]));
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
bool data = false;
for (int i = 0; i < capacity; i++)
Volatile.Write(ref data, bclContainer.Contains(values[i]));
}
}
struct ListIndexedRead : IBenchmarkContainer
{
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
UnsafeList<int> values;
public void AllocNativeContainer(int capacity)
{
ListUtil.AllocInt(ref nativeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
}
public void AllocUnsafeContainer(int capacity)
{
ListUtil.AllocInt(ref unsafeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
}
public object AllocBclContainer(int capacity)
{
object container = ListUtil.AllocBclContainer(capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
return container;
}
public void MeasureNativeContainer()
{
var reader = nativeContainer.AsReadOnly();
int insertions = values.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, reader[values[i]]);
}
public void MeasureUnsafeContainer()
{
int insertions = values.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, unsafeContainer[values[i]]);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
int insertions = values.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, bclContainer[values[i]]);
}
}
struct ListIndexedWrite : IBenchmarkContainer
{
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
UnsafeList<int> values;
public void AllocNativeContainer(int capacity)
{
ListUtil.AllocInt(ref nativeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
}
public void AllocUnsafeContainer(int capacity)
{
ListUtil.AllocInt(ref unsafeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
}
public object AllocBclContainer(int capacity)
{
object container = ListUtil.AllocBclContainer(capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
return container;
}
public void MeasureNativeContainer()
{
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
nativeContainer[values[i]] = i;
}
public void MeasureUnsafeContainer()
{
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer[values[i]] = i;
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
bclContainer[values[i]] = i;
}
}
struct ListRemove : IBenchmarkContainer
{
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
UnsafeList<int> values;
void FixValues()
{
// Ensure if we iterate this list and remove a random index, it will always be a valid index given how many elements still remain.
int max = values.Length;
while (--max >= 0)
{
int reverseIndex = values.Length - 1 - max;
int value = values[reverseIndex];
if (value > max)
values[reverseIndex] = max;
}
}
public void AllocNativeContainer(int capacity)
{
ListUtil.AllocInt(ref nativeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
FixValues();
}
public void AllocUnsafeContainer(int capacity)
{
ListUtil.AllocInt(ref unsafeContainer, capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
FixValues();
}
public object AllocBclContainer(int capacity)
{
object container = ListUtil.AllocBclContainer(capacity, true);
ListUtil.CreateRandomValues(capacity, ref values);
FixValues();
return container;
}
public void MeasureNativeContainer()
{
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
nativeContainer.RemoveAt(values[i]);
}
public void MeasureUnsafeContainer()
{
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer.RemoveAt(values[i]);
}
public void MeasureBclContainer(object container)
{
var bclContainer = (System.Collections.Generic.List<int>)container;
int insertions = values.Length;
for (int i = 0; i < insertions; i++)
bclContainer.RemoveAt(values[i]);
}
}
struct ListForEach : IBenchmarkContainer
{
NativeList<int> nativeContainer;
UnsafeList<int> unsafeContainer;
public int total;
public void AllocNativeContainer(int capacity) => ListUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ListUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ListUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer()
{
int value = 0;
foreach (var element in nativeContainer)
Volatile.Write(ref value, element);
}
public void MeasureUnsafeContainer()
{
int value = 0;
foreach (var element in unsafeContainer)
Volatile.Write(ref value, element);
}
public void MeasureBclContainer(object container)
{
int value = 0;
var bclContainer = (System.Collections.Generic.List<int>)container;
foreach (var element in bclContainer)
Volatile.Write(ref value, element);
}
}
[Benchmark(typeof(BenchmarkContainerType))]
class List
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(List))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(List));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void IsEmpty_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListIsEmpty100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Count_x_100k(
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListCount100k>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArray(
[Values(10000, 100000, 1000000)] int capacity,
[Values(BenchmarkContainerType.Native, BenchmarkContainerType.NativeBurstSafety,
BenchmarkContainerType.NativeBurstNoSafety)] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListToNativeArray>.Run(capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Add(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListAdd>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
[BenchmarkTestFootnote("Incrementally grows from `capacity` until reaching size of `growTo`")]
public unsafe void AddGrow(
[Values(4, 65536)] int capacity,
[Values(1024 * 1024)] int growTo,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListAddGrow>.Run(capacity, type, growTo);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Contains(
[Values(1000, 10000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListContains>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedRead(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListIndexedRead>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedWrite(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListIndexedWrite>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Remove(
[Values(1000, 10000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListRemove>.Run(insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunner<ListForEach>.Run(insertions, type);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38714c3d9f5dd4b4ba7fb2fd79dca07d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.Collections;
using Unity.PerformanceTesting;
namespace Unity.Collections.PerformanceTests
{
internal class NativeSlicePerformanceTests
{
[Test, Performance]
[Category("Performance")]
public void NativeSlice_Performance_CopyTo()
{
const int numElements = 16 << 10;
NativeArray<int> array = new NativeArray<int>(numElements, Allocator.Persistent);
var slice = new NativeSlice<int>(array, 0, numElements);
var copyToArray = new int[numElements];
Measure.Method(() =>
{
slice.CopyTo(copyToArray);
})
.WarmupCount(100)
.MeasurementCount(1000)
.Run();
array.Dispose();
}
[Test, Performance]
[Category("Performance")]
public void NativeSlice_Performance_CopyFrom()
{
const int numElements = 16 << 10;
NativeArray<int> array = new NativeArray<int>(numElements, Allocator.Persistent);
var slice = new NativeSlice<int>(array, 0, numElements);
var copyToArray = new int[numElements];
Measure.Method(() =>
{
slice.CopyFrom(copyToArray);
})
.WarmupCount(100)
.MeasurementCount(1000)
.Run();
array.Dispose();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d6cb74ab64d3d476393e420d9d74dec4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,932 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Unity.Collections.PerformanceTests
{
static class ParallelHashMapUtil
{
static public void AllocInt(ref NativeParallelHashMap<int, int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_1);
container = new NativeParallelHashMap<int, int>(capacity, Allocator.Persistent);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (container.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
}
else
container.Dispose();
}
static public void AllocInt(ref UnsafeParallelHashMap<int, int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_1);
container = new UnsafeParallelHashMap<int, int>(capacity, Allocator.Persistent);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (container.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
}
else
container.Dispose();
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_1);
// FROM MICROSOFT DOCUMENTATION
// The higher the concurrencyLevel, the higher the theoretical number of operations
// that could be performed concurrently on the ConcurrentDictionary. However, global
// operations like resizing the dictionary take longer as the concurrencyLevel rises.
// For the purposes of this example, we'll compromise at numCores * 2.
var bclContainer = new System.Collections.Concurrent.ConcurrentDictionary<int, int>(System.Environment.ProcessorCount * 2, capacity);
if (addValues)
{
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (bclContainer.TryAdd(randKey, keysAdded))
{
++keysAdded;
}
}
}
return bclContainer;
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref UnsafeParallelHashMap<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref System.Collections.Concurrent.ConcurrentDictionary<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys, ref NativeParallelHashMap<int, int> hashMap)
{
if (capacity >= 0)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
using (UnsafeHashSet<int> randomFilter = new UnsafeHashSet<int>(capacity, Allocator.Persistent))
{
Unity.Mathematics.Random random = new Unity.Mathematics.Random(HashMapUtil.K_RANDOM_SEED_2);
int keysAdded = 0;
while (keysAdded < capacity)
{
int randKey = random.NextInt();
if (randomFilter.TryAdd(randKey))
{
keys.Add(randKey);
++keysAdded;
}
}
}
}
else
keys.Dispose();
}
static public void RandomlyShuffleKeys(int capacity, ref UnsafeList<int> keys)
{
if (capacity >= 0)
{
Unity.Mathematics.Random random = new Mathematics.Random(HashMapUtil.K_RANDOM_SEED_3);
for (int i = 0; i < capacity; i++)
{
int keyAt = keys[i];
int randomIndex = random.NextInt(0, capacity - 1);
keys[i] = keys[randomIndex];
keys[randomIndex] = keyAt;
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public void SplitForWorkers(int count, int worker, int workers, out int startInclusive, out int endExclusive)
{
startInclusive = count * worker / workers;
endExclusive = count * (worker + 1) / workers;
}
}
struct ParallelHashMapIsEmpty100k : IBenchmarkContainerParallel
{
const int kIterations = 100_000;
int workers;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args) => workers = args[0];
public void AllocNativeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashMapUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = unsafeContainer.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = bclContainer.IsEmpty;
}
}
struct ParallelHashMapCount100k : IBenchmarkContainerParallel
{
const int kIterations = 100_000;
int workers;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args) => workers = args[0];
public void AllocNativeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashMapUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = reader.Count();
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = unsafeContainer.Count();
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = bclContainer.Count;
}
}
struct ParallelHashMapToNativeArrayKeys : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int worker, int threadIndex)
{
var asArray = nativeContainer.GetKeyArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
var asArray = unsafeContainer.GetKeyArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.Keys.CopyTo(asArray, 0);
}
}
struct ParallelHashMapToNativeArrayValues : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int worker, int threadIndex)
{
var asArray = nativeContainer.GetValueArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
var asArray = unsafeContainer.GetValueArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.Values.CopyTo(asArray, 0);
}
}
struct ParallelHashMapInsert : IBenchmarkContainerParallel
{
int capacity;
int workers;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
workers = args[0];
}
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
var writer = nativeContainer.AsParallelWriter();
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
writer.TryAdd(keys[i], i, threadIndex);
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
var writer = unsafeContainer.AsParallelWriter();
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
writer.TryAdd(keys[i], i, threadIndex);
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
bclContainer.TryAdd(keys[i], i);
}
}
struct ParallelHashMapAddGrow : IBenchmarkContainerParallel
{
int capacity;
int toAdd;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
toAdd = args[0] - capacity;
}
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
int toAddCount = capacity < 0 ? -1 : toAdd;
ParallelHashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref nativeContainer);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
int toAddCount = capacity < 0 ? -1 : toAdd;
ParallelHashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref unsafeContainer);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, true);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int toAddCount = capacity < 0 ? -1 : toAdd;
ParallelHashMapUtil.CreateRandomKeys(toAddCount, ref keys, ref bclContainer);
return container;
}
public void MeasureNativeContainer(int _, int __)
{
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
nativeContainer.Add(keys[i], i);
}
public void MeasureUnsafeContainer(int _, int __)
{
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
unsafeContainer.Add(keys[i], i);
}
public void MeasureBclContainer(object container, int _)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
// Intentionally setting capacity small and growing by adding more items
for (int i = 0; i < toAdd; i++)
bclContainer.TryAdd(keys[i], i);
}
}
struct ParallelHashMapContains : IBenchmarkContainerParallel
{
int capacity;
int workers;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
workers = args[0];
}
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, reader.ContainsKey(keys[i]));
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, unsafeContainer.ContainsKey(keys[i]));
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, bclContainer.ContainsKey(keys[i]));
}
}
struct ParallelHashMapIndexedRead : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, reader[keys[i]]);
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, unsafeContainer[keys[i]]);
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int insertions = keys.Length;
int value = 0;
for (int i = 0; i < insertions; i++)
Volatile.Write(ref value, bclContainer[keys[i]]);
}
}
struct ParallelHashMapIndexedWrite : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer[keys[i]] = i;
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer[keys[i]] = i;
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer[keys[i]] = i;
}
}
struct ParallelHashMapTryGetValue : IBenchmarkContainerParallel
{
int workers;
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args) => workers = args[0];
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashMapUtil.SplitForWorkers(keys.Length, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
{
reader.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashMapUtil.SplitForWorkers(keys.Length, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
{
unsafeContainer.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.SplitForWorkers(keys.Length, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
{
bclContainer.TryGetValue(keys[i], out var value);
Volatile.Read(ref value);
}
}
}
struct ParallelHashMapRemove : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashMapUtil.AllocBclContainer(capacity, false);
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
ParallelHashMapUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.TryAdd(keys[i], i);
ParallelHashMapUtil.RandomlyShuffleKeys(capacity, ref keys);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer.Remove(keys[i]);
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer.Remove(keys[i]);
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer.TryRemove(keys[i], out _);
}
}
struct ParallelHashMapForEach : IBenchmarkContainerParallel
{
NativeParallelHashMap<int, int> nativeContainer;
UnsafeParallelHashMap<int, int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashMapUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashMapUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int _, int __)
{
foreach (var pair in nativeContainer)
Volatile.Read(ref pair.Value);
}
public void MeasureUnsafeContainer(int _, int __)
{
foreach (var pair in unsafeContainer)
Volatile.Read(ref pair.Value);
}
public void MeasureBclContainer(object container, int _)
{
int value = 0;
var bclContainer = (System.Collections.Concurrent.ConcurrentDictionary<int, int>)container;
foreach (var pair in bclContainer)
Volatile.Write(ref value, pair.Value);
}
}
[Benchmark(typeof(BenchmarkContainerType))]
[BenchmarkNameOverride(BenchmarkContainerConfig.BCL, "ConcurrentDictionary")]
class ParallelHashMap
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(ParallelHashMap))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(ParallelHashMap));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void IsEmpty_x_100k(
[Values(1, 2, 4)] int workers,
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapIsEmpty100k>.Run(workers, capacity, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Count_x_100k(
[Values(1, 2, 4)] int workers,
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapCount100k>.Run(workers, capacity, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArrayKeys(
[Values(1)] int workers,
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapToNativeArrayKeys>.Run(workers, capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArrayValues(
[Values(1)] int workers,
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapToNativeArrayValues>.Run(workers, capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Insert(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapInsert>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
[BenchmarkTestFootnote("Incrementally grows from `capacity` until reaching size of `growTo`")]
public unsafe void AddGrow(
[Values(1)] int workers, // Can't grow capacity in parallel
[Values(4, 65536)] int capacity,
[Values(1024 * 1024)] int growTo,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapAddGrow>.Run(workers, capacity, type, growTo);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Contains(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapContains>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedRead(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapIndexedRead>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IndexedWrite(
[Values(1)] int workers, // Indexed write only available in single thread
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapIndexedWrite>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void TryGetValue(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapTryGetValue>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Remove(
[Values(1)] int workers, // No API for ParallelWriter.TryRemove currently
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapRemove>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(1)] int workers, // This work can't be split
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashMapForEach>.Run(workers, insertions, type, workers);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 646d50e1f45e86d4ea1fe9bfc488b347
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,802 @@
using NUnit.Framework;
using UnityEngine;
using Unity.Collections.LowLevel.Unsafe;
using Unity.PerformanceTesting;
using Unity.PerformanceTesting.Benchmark;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Unity.Collections.PerformanceTests
{
static class ParallelHashSetUtil
{
static public void AllocInt(ref NativeParallelHashSet<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new NativeParallelHashSet<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public void AllocInt(ref NativeParallelHashSet<int> containerA, ref NativeParallelHashSet<int> containerB, int capacity, bool addValues)
{
AllocInt(ref containerA, capacity, false);
AllocInt(ref containerB, capacity, false);
if (!addValues)
return;
for (int i = 0; i < capacity; i++)
{
containerA.Add(Random.Range(0, capacity * 2));
containerB.Add(Random.Range(0, capacity * 2));
}
}
static public void AllocInt(ref UnsafeParallelHashSet<int> container, int capacity, bool addValues)
{
if (capacity >= 0)
{
Random.InitState(0);
container = new UnsafeParallelHashSet<int>(capacity, Allocator.Persistent);
if (addValues)
{
for (int i = 0; i < capacity; i++)
container.Add(i);
}
}
else
container.Dispose();
}
static public void AllocInt(ref UnsafeParallelHashSet<int> containerA, ref UnsafeParallelHashSet<int> containerB, int capacity, bool addValues)
{
AllocInt(ref containerA, capacity, false);
AllocInt(ref containerB, capacity, false);
if (!addValues)
return;
for (int i = 0; i < capacity; i++)
{
containerA.Add(Random.Range(0, capacity * 2));
containerB.Add(Random.Range(0, capacity * 2));
}
}
static public object AllocBclContainer(int capacity, bool addValues)
{
if (capacity < 0)
return null;
Random.InitState(0);
var bclContainer = new FakeConcurrentHashSet<int>();
if (addValues)
{
for (int i = 0; i < capacity; i++)
bclContainer.Add(i);
}
return bclContainer;
}
static public object AllocBclContainerTuple(int capacity, bool addValues)
{
var tuple = new System.Tuple<FakeConcurrentHashSet<int>, FakeConcurrentHashSet<int>>(
(FakeConcurrentHashSet<int>)AllocBclContainer(capacity, false),
(FakeConcurrentHashSet<int>)AllocBclContainer(capacity, false));
if (addValues)
{
for (int i = 0; i < capacity; i++)
{
tuple.Item1.Add(Random.Range(0, capacity * 2));
tuple.Item2.Add(Random.Range(0, capacity * 2));
}
}
return tuple;
}
static public void CreateRandomKeys(int capacity, ref UnsafeList<int> keys)
{
if (!keys.IsCreated)
{
keys = new UnsafeList<int>(capacity, Allocator.Persistent);
Random.InitState(0);
for (int i = 0; i < capacity; i++)
{
int randKey = Random.Range(0, capacity);
keys.Add(randKey);
}
}
else
keys.Dispose();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public void SplitForWorkers(int count, int worker, int workers, out int startInclusive, out int endExclusive)
{
startInclusive = count * worker / workers;
endExclusive = count * (worker + 1) / workers;
}
}
// A generic HashSet with a lock is generally recommended as most performant way to obtain a thread safe HashSet in C#.
internal class FakeConcurrentHashSet<T> : System.IDisposable
{
private readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private readonly System.Collections.Generic.HashSet<T> m_HashSet = new System.Collections.Generic.HashSet<T>();
~FakeConcurrentHashSet() => Dispose(false);
public bool Add(T item)
{
m_Lock.EnterWriteLock();
try
{
return m_HashSet.Add(item);
}
finally
{
if (m_Lock.IsWriteLockHeld)
m_Lock.ExitWriteLock();
}
}
public void Clear()
{
m_Lock.EnterWriteLock();
try
{
m_HashSet.Clear();
}
finally
{
if (m_Lock.IsWriteLockHeld)
m_Lock.ExitWriteLock();
}
}
public bool Contains(T item)
{
m_Lock.EnterReadLock();
try
{
return m_HashSet.Contains(item);
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public bool Remove(T item)
{
m_Lock.EnterWriteLock();
try
{
return m_HashSet.Remove(item);
}
finally
{
if (m_Lock.IsWriteLockHeld)
m_Lock.ExitWriteLock();
}
}
public int Count
{
get
{
m_Lock.EnterReadLock();
try
{
return m_HashSet.Count;
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
}
public void CopyTo(T[] array)
{
m_Lock.EnterReadLock();
try
{
m_HashSet.CopyTo(array);
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public System.Collections.Generic.HashSet<T>.Enumerator GetEnumerator()
{
m_Lock.EnterReadLock();
try
{
return m_HashSet.GetEnumerator();
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public void UnionWith(FakeConcurrentHashSet<T> other)
{
m_Lock.EnterReadLock();
try
{
m_HashSet.UnionWith(other.m_HashSet);
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public void IntersectWith(FakeConcurrentHashSet<T> other)
{
m_Lock.EnterReadLock();
try
{
m_HashSet.IntersectWith(other.m_HashSet);
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public void ExceptWith(FakeConcurrentHashSet<T> other)
{
m_Lock.EnterReadLock();
try
{
m_HashSet.ExceptWith(other.m_HashSet);
}
finally
{
if (m_Lock.IsReadLockHeld)
m_Lock.ExitReadLock();
}
}
public void Dispose()
{
Dispose(true);
System.GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && m_Lock != null)
m_Lock.Dispose();
}
}
struct ParallelHashSetIsEmpty100k : IBenchmarkContainerParallel
{
const int kIterations = 100_000;
int workers;
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args) => workers = args[0];
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = reader.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = unsafeContainer.IsEmpty;
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = bclContainer.Count == 0;
}
}
struct ParallelHashSetCount100k : IBenchmarkContainerParallel
{
const int kIterations = 100_000;
int workers;
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args) => workers = args[0];
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, true);
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = reader.Count();
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = unsafeContainer.Count();
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.SplitForWorkers(kIterations, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
_ = bclContainer.Count;
}
}
struct ParallelHashSetToNativeArray : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int worker, int threadIndex)
{
var asArray = nativeContainer.ToNativeArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
var asArray = unsafeContainer.ToNativeArray(Allocator.Temp);
asArray.Dispose();
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
int[] asArray = new int[bclContainer.Count];
bclContainer.CopyTo(asArray);
}
}
struct ParallelHashSetInsert : IBenchmarkContainerParallel
{
int capacity;
int workers;
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
workers = args[0];
}
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, false);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, false);
public void MeasureNativeContainer(int worker, int threadIndex)
{
var writer = nativeContainer.AsParallelWriter();
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
writer.Add(i, threadIndex);
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
var writer = unsafeContainer.AsParallelWriter();
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
writer.Add(i, threadIndex);
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
for (int i = start; i < end; i++)
bclContainer.Add(i);
}
}
struct ParallelHashSetAddGrow : IBenchmarkContainerParallel
{
int capacity;
int toAdd;
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
toAdd = args[0] - capacity;
}
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int _, int __)
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
nativeContainer.Add(i);
}
public void MeasureUnsafeContainer(int _, int __)
{
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
unsafeContainer.Add(i);
}
public void MeasureBclContainer(object container, int _)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
// Intentionally setting capacity small and growing by adding more items
for (int i = capacity; i < capacity + toAdd; i++)
bclContainer.Add(i);
}
}
struct ParallelHashSetContains : IBenchmarkContainerParallel
{
int capacity;
int workers;
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
UnsafeList<int> keys;
void IBenchmarkContainerParallel.SetParams(int capacity, params int[] args)
{
this.capacity = capacity;
workers = args[0];
}
public void AllocNativeContainer(int capacity)
{
ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.Add(keys[i]);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(keys[i]);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashSetUtil.AllocBclContainer(capacity, false);
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.Add(keys[i]);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
var reader = nativeContainer.AsReadOnly();
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, reader.Contains(keys[i]));
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, unsafeContainer.Contains(keys[i]));
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.SplitForWorkers(capacity, worker, workers, out int start, out int end);
bool data = false;
for (int i = start; i < end; i++)
Volatile.Write(ref data, bclContainer.Contains(keys[i]));
}
}
struct ParallelHashSetRemove : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
UnsafeList<int> keys;
public void AllocNativeContainer(int capacity)
{
ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, false);
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
nativeContainer.Add(keys[i]);
}
public void AllocUnsafeContainer(int capacity)
{
ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, false);
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
unsafeContainer.Add(keys[i]);
}
public object AllocBclContainer(int capacity)
{
object container = ParallelHashSetUtil.AllocBclContainer(capacity, false);
var bclContainer = (FakeConcurrentHashSet<int>)container;
ParallelHashSetUtil.CreateRandomKeys(capacity, ref keys);
for (int i = 0; i < capacity; i++)
bclContainer.Add(keys[i]);
return container;
}
public void MeasureNativeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
nativeContainer.Remove(keys[i]);
}
public void MeasureUnsafeContainer(int worker, int threadIndex)
{
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
unsafeContainer.Remove(keys[i]);
}
public void MeasureBclContainer(object container, int worker)
{
var bclContainer = (FakeConcurrentHashSet<int>)container;
int insertions = keys.Length;
for (int i = 0; i < insertions; i++)
bclContainer.Remove(keys[i]);
}
}
struct ParallelHashSetForEach : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
UnsafeParallelHashSet<int> unsafeContainer;
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainer(capacity, true);
public void MeasureNativeContainer(int _, int __)
{
int keep = 0;
foreach (var value in nativeContainer)
Volatile.Write(ref keep, value);
}
public void MeasureUnsafeContainer(int _, int __)
{
int keep = 0;
foreach (var value in unsafeContainer)
Volatile.Write(ref keep, value);
}
public void MeasureBclContainer(object container, int _)
{
int keep = 0;
var bclContainer = (FakeConcurrentHashSet<int>)container;
foreach (var value in bclContainer)
Volatile.Write(ref keep, value);
}
}
struct ParallelHashSetUnionWith : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
NativeParallelHashSet<int> nativeContainerOther;
UnsafeParallelHashSet<int> unsafeContainer;
UnsafeParallelHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer(int _, int __) => nativeContainer.UnionWith(nativeContainerOther);
public void MeasureUnsafeContainer(int _, int __) => unsafeContainer.UnionWith(unsafeContainerOther);
public void MeasureBclContainer(object container, int _)
{
var dotnetContainer = (System.Tuple<FakeConcurrentHashSet<int>, FakeConcurrentHashSet<int>>)container;
dotnetContainer.Item1.UnionWith(dotnetContainer.Item2);
}
}
struct ParallelHashSetIntersectWith : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
NativeParallelHashSet<int> nativeContainerOther;
UnsafeParallelHashSet<int> unsafeContainer;
UnsafeParallelHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer(int _, int __) => nativeContainer.IntersectWith(nativeContainerOther);
public void MeasureUnsafeContainer(int _, int __) => unsafeContainer.IntersectWith(unsafeContainerOther);
public void MeasureBclContainer(object container, int _)
{
var dotnetContainer = (System.Tuple<FakeConcurrentHashSet<int>, FakeConcurrentHashSet<int>>)container;
dotnetContainer.Item1.IntersectWith(dotnetContainer.Item2);
}
}
struct ParallelHashSetExceptWith : IBenchmarkContainerParallel
{
NativeParallelHashSet<int> nativeContainer;
NativeParallelHashSet<int> nativeContainerOther;
UnsafeParallelHashSet<int> unsafeContainer;
UnsafeParallelHashSet<int> unsafeContainerOther;
public int total;
public void AllocNativeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref nativeContainer, ref nativeContainerOther, capacity, true);
public void AllocUnsafeContainer(int capacity) => ParallelHashSetUtil.AllocInt(ref unsafeContainer, ref unsafeContainerOther, capacity, true);
public object AllocBclContainer(int capacity) => ParallelHashSetUtil.AllocBclContainerTuple(capacity, true);
public void MeasureNativeContainer(int _, int __) => nativeContainer.ExceptWith(nativeContainerOther);
public void MeasureUnsafeContainer(int _, int __) => unsafeContainer.ExceptWith(unsafeContainerOther);
public void MeasureBclContainer(object container, int _)
{
var dotnetContainer = (System.Tuple<FakeConcurrentHashSet<int>, FakeConcurrentHashSet<int>>)container;
dotnetContainer.Item1.ExceptWith(dotnetContainer.Item2);
}
}
[Benchmark(typeof(BenchmarkContainerType))]
[BenchmarkNameOverride(BenchmarkContainerConfig.BCL, "HashSet w/lock")]
class ParallelHashSet
{
#if UNITY_EDITOR
[UnityEditor.MenuItem(BenchmarkContainerConfig.kMenuItemIndividual + nameof(ParallelHashSet))]
static void RunIndividual()
=> BenchmarkContainerConfig.RunBenchmark(typeof(ParallelHashSet));
#endif
[Test, Performance]
[Category("Performance")]
public unsafe void IsEmpty_x_100k(
[Values(1, 2, 4)] int workers,
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetIsEmpty100k>.Run(workers, capacity, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Count_x_100k(
[Values(1, 2, 4)] int workers,
[Values(0, 100)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetCount100k>.Run(workers, capacity, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ToNativeArray(
[Values(1)] int workers,
[Values(10000, 100000, 1000000)] int capacity,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetToNativeArray>.Run(workers, capacity, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Insert(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetInsert>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
[BenchmarkTestFootnote("Incrementally grows from `capacity` until reaching size of `growTo`")]
public unsafe void AddGrow(
[Values(1)] int workers, // Can't grow capacity in parallel
[Values(4, 65536)] int capacity,
[Values(1024 * 1024)] int growTo,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetAddGrow>.Run(workers, capacity, type, growTo);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Contains(
[Values(1, 2, 4)] int workers,
#if UNITY_STANDALONE || UNITY_EDITOR
[Values(10000, 100000, 1000000)] int insertions,
#else
[Values(10000, 100000)] int insertions, // Observe potential lower memory requirement on non-desktop platforms
#endif
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetContains>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Remove(
[Values(1)] int workers, // No API for ParallelWriter.TryRemove currently
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetRemove>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void Foreach(
[Values(1)] int workers, // This work can't be split
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetForEach>.Run(workers, insertions, type, workers);
}
[Test, Performance]
[Category("Performance")]
public unsafe void UnionWith(
[Values(1)] int workers, // This work is already split and unrelated to the parallelism of the container
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetUnionWith>.Run(workers, insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void IntersectWith(
[Values(1)] int workers, // This work is already split and unrelated to the parallelism of the container
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetIntersectWith>.Run(workers, insertions, type);
}
[Test, Performance]
[Category("Performance")]
public unsafe void ExceptWith(
[Values(1)] int workers, // This work is already split and unrelated to the parallelism of the container
[Values(10000, 100000, 1000000)] int insertions,
[Values] BenchmarkContainerType type)
{
BenchmarkContainerRunnerParallel<ParallelHashSetExceptWith>.Run(workers, insertions, type);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 658c5e8f30c4cbe4b88301ce6599a6fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
fileFormatVersion: 2
guid: 079c3d43b74823a41bb33198b8221c23
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
fileFormatVersion: 2
guid: a6ecd2aa79759e64ba59ab5f51d661ac
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More