giraffe-fsharp / Giraffe

A native functional ASP.NET Core web framework for F# developers.
https://giraffe.wiki
Apache License 2.0
2.13k stars 266 forks source link

Benchmark `WriteBytesAsync` optimization #601

Closed 64J0 closed 4 months ago

64J0 commented 4 months ago

Description

With this PR, I'm adding a simple code used to benchmark PR https://github.com/giraffe-fsharp/Giraffe/pull/600, inspired by this test.

For now, I don't have the intention to merge this PR.

Results from my local environment:

# how to run
cd benchmarks/
sudo dotnet run -c Release
// * Summary *

BenchmarkDotNet v0.13.10, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
Intel Core i7-7500U CPU 2.70GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.202
  [Host]     : .NET 8.0.3 (8.0.324.11423), X64...
  DefaultJob : .NET 8.0.3 (8.0.324.11423), X64...
Method ListSize Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
V1 100 26.07 us 0.497 us 0.553 us 1.00 0.00 4.3945 1.0986 27.38 KB 1.00
V2 100 26.36 us 0.517 us 0.484 us 1.01 0.02 4.4556 1.1292 27.38 KB 1.00
V1 500 85.47 us 0.843 us 0.704 us 1.00 0.00 144.0430 9.5215 298.14 KB 1.00
V2 500 85.74 us 1.224 us 1.085 us 1.00 0.02 144.0430 9.5215 298.14 KB 1.00
V1 1000 228.97 us 4.474 us 4.394 us 1.00 0.00 524.9023 14.1602 1076.04 KB 1.00
V2 1000 228.11 us 3.399 us 3.013 us 1.00 0.02 524.9023 14.1602 1076.04 KB 1.00
V1 5000 2,892.29 us 34.598 us 32.363 us 1.00 0.00 12000.0000 300.7813 24876.91 KB 1.00
V2 5000 2,889.10 us 40.907 us 36.263 us 1.00 0.02 12000.0000 300.7813 24876.91 KB 1.00
// * Hints *
Outliers
  WriteBytesAsync.V1: Default -> 2 outliers were removed (88.32 us, 95.53 us)
  WriteBytesAsync.V2: Default -> 1 outlier  was  removed (96.43 us)
  WriteBytesAsync.V1: Default -> 3 outliers were removed (250.95 us..253.84 us)
  WriteBytesAsync.V2: Default -> 1 outlier  was  removed (254.30 us)
  WriteBytesAsync.V2: Default -> 1 outlier  was  removed (2.98 ms)

// * Legends *
  ListSize    : Value of the 'ListSize' parameter
  Mean        : Arithmetic mean of all measurements
  Error       : Half of 99.9% confidence interval
  StdDev      : Standard deviation of all measurements
  Ratio       : Mean of the ratio distribution ([Current]/[Baseline])
  RatioSD     : Standard deviation of the ratio distribution ([Current]/[Baseline])
  Gen0        : GC Generation 0 collects per 1000 operations
  Gen1        : GC Generation 1 collects per 1000 operations
  Allocated   : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
  Alloc Ratio : Allocated memory ratio distribution ([Current]/[Baseline])
  1 us        : 1 Microsecond (0.000001 sec)