From f243320c531c4151bd58718f7cc450b3b2e5eae6 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Sun, 5 Dec 2021 21:34:21 +0100 Subject: [PATCH] Add benchmarks --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index adb0340..5276d1c 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,16 @@ The algorithm is described in [Faster Base64 Encoding and Decoding Using AVX2 Instructions](https://arxiv.org/abs/1704.00605) by Wojciech Muła and Daniel Lemire. -Benchmarks show that this implementation is about 8-10 times faster -than the standard .NET implementation +Benchmarks (see below) show that this implementation is +about 8-10 times faster than the standard .NET implementation in `System.Convert.TryToBase64Chars()` and `System.Convert.TryFromBase64Chars()`. We provide re-implementations of these two methods within a static class `FasterBase64.Convert`. + * `FasterBase64.Convert.TryToBase64Chars()` works the same way as `System.Convert.TryToBase64Chars()`; -* `System.FasterBase64.TryFromBase64Chars()` works +* `FasterBase64.FasterBase64.TryFromBase64Chars()` works the same way as`System.Convert.TryFromBase64Chars()`, if the input does not contain whitespace. The standard .NET implementation differs from the RFC4648 standard in that it allows whitespace in the data. @@ -23,15 +24,53 @@ within a static class `FasterBase64.Convert`. We believe that (in all reasonable cases) this is still faster than using the standard implementation. -Caveats: +## Benchmarks for encoding + +AMD Ryzen 9 3950X 16-Core Processor, 3493 Mhz, +Windows 10.0.22509, .NET 6.0.0 (6.0.21.52210) + +| Method | N | Mean | Error | StdDev | +|------- |------ |------------:|----------:|----------:| +| Old | 100 | 95.05 ns | 0.758 ns | 0.672 ns | +| New | 100 | 25.06 ns | 0.507 ns | 0.498 ns | +| Old | 1000 | 872.76 ns | 11.321 ns | 10.036 ns | +| New | 1000 | 92.05 ns | 0.633 ns | 0.592 ns | +| Old | 10000 | 8,723.65 ns | 79.673 ns | 74.526 ns | +| New | 10000 | 724.58 ns | 9.693 ns | 9.067 ns | + +Here "Old" denotes usage of `System.Convert.TryToBase64Chars()`, +"New" denotes usage of `FasterBase64.Convert.TryToBase64Chars()`, +"N" is the size of input byte array. + +## Benchmarks for decoding + +AMD Ryzen 9 3950X 16-Core Processor, 3493 Mhz, +Windows 10.0.22509, .NET 6.0.0 (6.0.21.52210) + +| Method | N | Mean | Error | StdDev | +|------- |------ |------------:|----------:|----------:| +| Old | 100 | 94.66 ns | 0.839 ns | 0.743 ns | +| New | 100 | 54.08 ns | 0.547 ns | 0.457 ns | +| Old | 1000 | 831.63 ns | 9.560 ns | 8.474 ns | +| New | 1000 | 131.31 ns | 1.085 ns | 0.906 ns | +| Old | 10000 | 8,254.94 ns | 64.406 ns | 57.094 ns | +| New | 10000 | 1,011.61 ns | 6.320 ns | 5.602 ns | + +Here "Old" denotes usage of `System.Convert.TryFromBase64Chars()`, +"New" denotes usage of `FasterBase64.Convert.TryFromBase64Chars()`, +"N" is the size of byte array, that is then encoded in base64 using +`System.Convert.TryToBase64Chars()` to form input to the +benchmarked methods. + +## Caveats * Although we believe the implementation to be reasonably well tested, there might still be bugs. * The implementation uses AVX2 instructions, but does not check if AVX2 is available. AVX2 support can be easily checked by querying the property `System.Runtime.Intrinsics.X86.Avx2.IsSupported`. -TODO: +## TODO * NuGet package. -License: +## License * Copyright (c) Alexander Luzgarev, 2021, under the GPL license.