Performance benchmarks for SharpToken
mainSharpToken provides performance benchmarks comparing its methods (Encode, CountTokens, and CountTokens_LargeInput) across different .NET runtimes: .NET 8.0, .NET 6.0, and .NET Framework 4.7.1.
Key performance observations:
- .NET 8.0 Optimization: The library is highly optimized for .NET 8.0. For example,
CountTokens_LargeInputon .NET 8.0 allocates only 75 B and is significantly faster than on older runtimes. - Allocation Efficiency: Recent improvements (v1.2.17+) have focused on reducing minor allocations, particularly for the
CountTokensmethod in .NET 8.0, which can achieve near-zero allocation (approx. 4.06 KB). - Runtime Comparison: .NET 8.0 consistently shows the lowest
Meanexecution time and lowestAllocatedmemory across all tested methods compared to .NET 6.0 and .NET Framework 4.7.1.