From 1fadf5ea50f2dbf309c9b4b00dc5c7fd577861b1 Mon Sep 17 00:00:00 2001 From: IncSW Date: Wed, 18 Aug 2021 14:39:42 +0300 Subject: [PATCH] update benchmarks --- README.md | 22 ++++++++++++---------- decoder_test.go | 16 ---------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b28700c..ab71494 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Faster base64 encoding for Go, based on [Turbo-Base64](https://github.com/powtur * Drop-in replacement of `encoding/base64`. * _except for error messages and ignoring `\r` and `\n` in decoder._ -* ~3 times faster than `encoding/base64`. +* up to 3 times faster than `encoding/base64`. * Dependency-free. ## Install @@ -33,16 +33,18 @@ Replace import statement from `encoding/base64` to `github.com/cristalhq/base64` # Benchmarks +go1.17 linux/amd64, Intel i7-7700 + ``` -std/Encode 674.7 ns/op 0 B/op 0 allocs/op -std/EncodeToString 943.3 ns/op 2014 B/op 2 allocs/op -std/Decode 747.8 ns/op 0 B/op 0 allocs/op -std/DecodeString 1012 ns/op 1792 B/op 2 allocs/op - -own/Encode 215.3 ns/op 0 B/op 0 allocs/op -own/EncodeToString 354.6 ns/op 1024 B/op 1 allocs/op -own/Decode 306.6 ns/op 0 B/op 0 allocs/op -own/DecodeString 440.0 ns/op 768 B/op 1 allocs/op +std/Encode 685.3 ns/op 0 B/op 0 allocs/op +std/EncodeToString 951.8 ns/op 2048 B/op 2 allocs/op +std/Decode 803.9 ns/op 0 B/op 0 allocs/op +std/DecodeString 1061 ns/op 1792 B/op 2 allocs/op + +own/Encode 217.8 ns/op 0 B/op 0 allocs/op +own/EncodeToString 353.2 ns/op 1024 B/op 1 allocs/op +own/Decode 376.3 ns/op 0 B/op 0 allocs/op +own/DecodeString 507.1 ns/op 768 B/op 1 allocs/op ``` ## Documentation diff --git a/decoder_test.go b/decoder_test.go index 5042a69..1a1c466 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -159,19 +159,3 @@ func BenchmarkDecoder(b *testing.B) { } }) } - -func BenchmarkDecoder2(b *testing.B) { - b.ReportAllocs() - var err error - - length := StdEncoding.DecodedLen(len(stdBase64ValueBytes)) - byteResult = make([]byte, length) - b.Run("own/Decode", func(b *testing.B) { - for n := 0; n < b.N; n++ { - resultN, err = StdEncoding.Decode(byteResult, stdBase64ValueBytes) - if err != nil { - b.Fatal() - } - } - }) -}