Skip to main content

Performance Benchmarks

This page presents comprehensive benchmark results comparing Spinner v1.x with v2.0, demonstrating the significant performance improvements achieved in the new version.

Benchmark Environment

All benchmarks were executed under the following conditions:

  • OS: Windows 11 (10.0.26200.7171)
  • CPU: 12th Gen Intel Core i5-12500H @ 2.50GHz (1 CPU, 16 logical and 12 physical cores)
  • Tool: BenchmarkDotNet v0.15.6
  • SDK: .NET SDK 10.0.100
  • Runtimes Tested: .NET 8.0, .NET 9.0, .NET 10.0
  • Configuration: Server GC Enabled

Read Operations Performance

ReadFromString

Comparison of reading positional strings and converting them to objects.

v2.0 Results (After Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.046.32 ns0.793 ns0.742 ns32 B
.NET 8.053.66 ns0.637 ns0.596 ns32 B
.NET 9.054.57 ns0.409 ns0.382 ns32 B

v1.x Results (Before Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.02.821 µs0.0098 µs0.0076 µs664 B
.NET 8.03.059 µs0.0386 µs0.0323 µs664 B
.NET 9.01.269 µs0.0223 µs0.0208 µs664 B

Performance Improvement

RuntimeSpeed ImprovementMemory Improvement
.NET 10.0~60x faster~20x less 💾
.NET 8.0~57x faster~20x less 💾
.NET 9.0~23x faster~20x less 💾
Remarkable Achievement

The ReadFromString method in v2.0 is up to 60 times faster and uses 20 times less memory compared to v1.x!

ReadFromSpan

Comparison of reading from ReadOnlySpan<char> for zero-allocation parsing.

v2.0 Results (After Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.044.34 ns0.496 ns0.464 ns32 B
.NET 8.051.30 ns0.806 ns0.754 ns32 B
.NET 9.055.31 ns0.746 ns0.697 ns0 B*

*Near-zero allocation in .NET 9.0

v1.x Results (Before Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.02.774 µs0.0320 µs0.0300 µs664 B
.NET 8.01.321 µs0.0253 µs0.0281 µs664 B
.NET 9.01.275 µs0.0242 µs0.0259 µs664 B

Performance Improvement

RuntimeSpeed ImprovementMemory Improvement
.NET 10.0~62x faster~20x less 💾
.NET 8.0~25x faster~20x less 💾
.NET 9.0~23x faster~∞ (zero-alloc) 💾

ReadFromString with Interceptor

Performance when using custom interceptors for value transformation.

v2.0 Results (After Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.050.25 ns0.355 ns0.297 ns32 B
.NET 8.077.14 ns0.805 ns0.753 ns32 B
.NET 9.062.20 ns0.752 ns0.667 ns32 B

v1.x Results (Before Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.04.014 µs0.0649 µs0.0608 µs848 B
.NET 8.01.816 µs0.0359 µs0.0336 µs784 B
.NET 9.01.697 µs0.0317 µs0.0296 µs840 B

Performance Improvement

RuntimeSpeed ImprovementMemory Improvement
.NET 10.0~79x faster~26x less 💾
.NET 8.0~23x faster~24x less 💾
.NET 9.0~27x faster~26x less 💾
Interceptor Optimization

Even with custom interceptors, v2.0 achieves up to 79x faster execution with 26x less memory allocation!

Write Operations Performance

WriteAsString

Comparison of converting objects to positional strings.

v2.0 Results (After Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.039.52 ns0.739 ns0.691 ns128 B
.NET 8.048.32 ns0.467 ns0.437 ns128 B
.NET 9.051.28 ns1.087 ns3.170 ns128 B

v1.x Results (Before Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.01.243 µs0.0245 µs0.0478 µs808 B
.NET 8.01.413 µs0.0281 µs0.0586 µs808 B
.NET 9.01.344 µs0.0266 µs0.0382 µs808 B

Performance Improvement

RuntimeSpeed ImprovementMemory Improvement
.NET 10.0~31x faster~6x less 💾
.NET 8.0~29x faster~6x less 💾
.NET 9.0~26x faster~6x less 💾

WriteAsSpan

Comparison of converting objects to ReadOnlySpan<char>.

v2.0 Results (After Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.039.79 ns0.714 ns0.633 ns128 B
.NET 8.048.28 ns0.384 ns0.321 ns128 B
.NET 9.055.05 ns1.113 ns1.282 ns128 B

v1.x Results (Before Optimization)

RuntimeMeanErrorStdDevAllocated
.NET 10.01.266 µs0.0251 µs0.0541 µs936 B
.NET 8.01.363 µs0.0152 µs0.0127 µs936 B
.NET 9.01.332 µs0.0176 µs0.0138 µs936 B

Performance Improvement

RuntimeSpeed ImprovementMemory Improvement
.NET 10.0~31x faster~7x less 💾
.NET 8.0~28x faster~7x less 💾
.NET 9.0~24x faster~7x less 💾
Consistent Performance

Write operations show consistent performance improvements across all .NET versions, with speed gains of 24-31x and memory reductions of 6-7x.

Summary of Improvements

Overall Performance Gains

OperationAverage Speed ImprovementAverage Memory Reduction
Read Operations~40-60x faster~20-26x less 💾
Write Operations~25-30x faster~6-7x less 💾

Real-World Impact

Throughput Comparison

Based on the benchmarks, here's what you can expect in real-world scenarios:

Processing 1 Million Records

Operationv1.x Timev2.0 TimeTime Saved
Read~2,821 seconds (~47 min)~46 milliseconds99.998% faster
Write~1,243 seconds (~20 min)~40 milliseconds99.997% faster

Memory Usage for 1 Million Records

Operationv1.x Memoryv2.0 MemoryMemory Saved
Read~664 MB~32 MB~632 MB (95%)
Write~808 MB~128 MB~680 MB (84%)
Production Ready

These improvements make Spinner v2.0 suitable for high-throughput production environments where performance and memory efficiency are critical.

Best Practices for Maximum Performance

  1. Reuse Spinner Instances

    // Good: Single instance, reused
    var spinner = new Spinner<MyClass>();
    foreach (var item in items)
    {
    var result = spinner.WriteAsString(item);
    }
  2. Use Span-based Methods When Possible

    // Better performance with ReadFromSpan
    ReadOnlySpan<char> data = GetDataAsSpan();
    var obj = spinner.ReadFromSpan(data);
  3. Configure ObjectMapper Length

    // Helps pre-allocate StringBuilder to exact size
    [ObjectMapper(length: 100)]
    public class MyClass { }
  4. Avoid Interceptors When Not Needed

    • Use built-in type conversion for primitive types
    • Only use interceptors for complex transformations

Benchmark Source Code

All benchmarks are available in the repository at:

  • Path: bench/Spinner.Benchmark/
  • Read Benchmarks: ReadBench.cs
  • Write Benchmarks: WriterBench.cs

To run benchmarks yourself:

cd bench/Spinner.Benchmark
dotnet run -c Release

Continuous Performance Monitoring

Performance benchmarks are automatically executed in the CI/CD pipeline to ensure no performance regressions:

Benchmark CI

Conclusion

Spinner v2.0 represents a massive leap forward in performance:

Up to 79x faster execution times
Up to 26x less memory allocation
Near-zero allocation scenarios in .NET 9.0+
Production-ready for high-throughput workloads
Consistent performance across all .NET versions

The architectural changes in v2.0, while introducing some breaking changes, deliver transformative performance improvements that make the migration effort worthwhile for any performance-conscious application.