Skip to content

Commit

Permalink
Add original implementation for benchmarking.
Browse files Browse the repository at this point in the history
For #1.
  • Loading branch information
kevina committed Nov 21, 2016
1 parent 84ef217 commit a5bba06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions base32.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package base32
import (
"io"
"strconv"
"strings"
)

/*
Expand Down Expand Up @@ -382,6 +383,20 @@ func (enc *Encoding) DecodeString(s string) ([]byte, error) {
return strb[:n], nil
}

var removeNewlinesMapper = func(r rune) rune {
if r == '\r' || r == '\n' {
return -1
}
return r
}

func (enc *Encoding) DecodeStringOrig(s string) ([]byte, error) {
s = strings.Map(removeNewlinesMapper, s)
dbuf := make([]byte, enc.DecodedLen(len(s)))
n, _, err := enc.decode(dbuf, []byte(s))
return dbuf[:n], err
}

// DecodeString returns the bytes represented by the base32 string s.
func (enc *Encoding) DecodeStringKevOrig(s string) ([]byte, error) {
stripped := make([]byte, 0, len(s))
Expand Down
12 changes: 11 additions & 1 deletion base32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,19 @@ func TestNoPaddingRand(t *testing.T) {

var keyLen = 55
var sampleKey = RandomBase32String(keyLen)
var sampleKeyBytes = []byte(sampleKey)
//var sampleKeyBytes = []byte(sampleKey)
//var sampleKey = "BP\rH3BGZMIEGPCRY2LVF\nCP2IS7LPYWXVY3PFMJ\rX5SNSKDRT6E7ZVJVXI"

func BenchmarkKeyDecodeOrig(b *testing.B) {
key := sampleKey
for i := 0; i < b.N; i++ {
_,err := RawStdEncoding.DecodeStringOrig(key)
if err != nil {
panic(err)
}
}
}

func BenchmarkKeyDecodeKevOrig(b *testing.B) {
key := sampleKey
for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit a5bba06

Please sign in to comment.