Microbenchmarks are important part of DotNext library to prove than important features can speed up performance of your application or, at least, is not slowing down it.
The configuration of all benchmarks:
Parameter Configuration Runtime .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2 LaunchCount 1 RunStrategy Throughput OS Ubuntu 22.04.3 CPU Intel Core i7-6700HQ CPU 2.60GHz (Skylake) Number of CPUs 1 Physical Cores 4 Logical Cores 8 RAM 24 GBYou can run benchmarks using Bench
build configuration as follows:
cd <dotnext-clone-path>/src/DotNext.Benchmarks
dotnet run -c Bench
Bitwise Hash Code
This benchmark compares performance of BitwiseComparer<T>.GetHashCode and GetHashCode
instance method for the types Guid and custom value type with multiple fields.
Guid.GetHashCode
0.6889 ns 0.0085 ns 0.0076 ns BitwiseComparer<Guid>.GetHashCode
6.3194 ns 0.0223 ns 0.0209 ns BitwiseComparer<LargeStructure>.GetHashCode
20.6265 ns 0.0839 ns 0.0785 ns LargeStructure.GetHashCode
43.5677 ns 0.1517 ns 0.1419 ns
Bitwise hash code algorithm is slower than JIT optimizations introduced by .NET 6 but still convenient in complex cases.
Bytes to HexThis benchmark demonstrates performance of extension methods declared in DotNext.Buffers.Text.Hex
class that allows to convert arbitrary set of bytes to hexadecimal form.
This benchmark compares performance of Atomic<T> and Synchronized methods. The implementation of the benchmark contains concurrent read/write threads to ensure that lock contention is in place.
Method Mean Error StdDev Median Atomic 589.5 us 11.30 us 105.0 us 576.9 us Synchronized 1,005.4 us 12.59 us 117.3 us 981.7 us SpinLock 1,359.3 us 65.59 us 628.4 us 1,573.7 us File-buffering WriterThis benchmark compares performance of FileBufferingWriteStream from ASP.NET Core and FileBufferingWriter from .NEXT library.
Both classes switching from in-memory buffer to file-based buffer during benchmark execution. Note that benchmark result highly depends on disk I/O performance. The following results were obtained using NVMe SSD.
Method Mean Error StdDev Gen0 Gen1 Gen2 Allocated 'FileBufferingWriter, synchronous mode' 934.7 us 8.52 us 7.97 us 250.0000 249.0234 249.0234 1 MB 'FileBufferingWriter, asynchronous mode' 1,306.9 us 25.69 us 44.31 us 195.3125 195.3125 195.3125 1 MB 'FileBufferingWriteStream, synchronouse mode' 3,548.1 us 30.80 us 25.72 us 402.3438 289.0625 250.0000 1.5 MB 'FileBufferingWriteStream, asynchronous mode' 4,054.6 us 42.32 us 39.59 us 375.0000 289.0625 242.1875 1.5 MBFileBufferingWriter
is a winner in synchronous scenario because it has native support for synchronous mode in contrast to FileBufferingWriteStream
.
This benchmark demonstrates the performance of write operation and memory consumption of the following types:
TypeMap<TValue> and ConcurrentTypeMap<TValue> are specialized dictionaries where the keys are represented by the types passed as generic arguments. The are optimized in a way to be more performant than classic Dictionary<Type,TValue> and ConcurrentDictionary<Type,TValue>. This benchmark demonstrates efficiency of the specialized collections:
Method Mean Error StdDev 'TypeMap, Set + TryGetValue' 3.647 ns 0.0260 ns 0.0243 ns 'Dictionary, Set + TryGetValue' 33.777 ns 0.1140 ns 0.1010 ns 'ConcurrentTypeMap, Set + TryGetValue' 21.542 ns 0.1108 ns 0.0982 ns 'ConcurrentDictionary, Set + TryGetValue' 59.608 ns 0.3600 ns 0.3191 ns 'ConcurrentTypeMap, GetOrAdd' 10.249 ns 0.0435 ns 0.0407 ns 'ConcurrentDictionary, GetOrAdd' 16.019 ns 0.0739 ns 0.0692 ns TaskCompletionPipeThis benchmark demonstrates efficiency of Task Completion Pipe versus async channels from .NET. Pipe sorts the submitted tasks in order of their completion in time. The fastest result is available immediately for the consumer, while the channel needs to wait for completion of the task and only then add it to the queue.
Method Number of input tasks Mean Error StdDev Ratio RatioSD ProduceConsumeCompletionPipe 10 9.420 us 0.0787 us 0.0736 us 0.65 0.02 ProduceConsumeUnboundedChannel 10 14.449 us 0.2887 us 0.3651 us 1.00 0.00 ProduceConsumeCompletionPipe 100 75.802 us 1.4586 us 1.4326 us 0.62 0.01 ProduceConsumeUnboundedChannel 100 123.375 us 0.7581 us 0.6720 us 1.00 0.00 ProduceConsumeCompletionPipe 1000 707.746 us 9.2224 us 8.6266 us 0.66 0.01 ProduceConsumeUnboundedChannel 1000 1,073.418 us 5.2448 us 4.9060 us 1.00 0.00RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4