ssg / SimpleBase

.NET library for encoding/decoding Base16, Base32, Base58 and Base85.
Apache License 2.0
147 stars 21 forks source link

Increase Base16 Encoder performance #7

Closed shtse8 closed 6 years ago

shtse8 commented 6 years ago

This is an amazing package and solve me lots of base encoding problems. Thanks for your contribution.

I have used the following hex encoder. It seems he is using mapping table to encode and decode base16. Do you think it will help improve the speed comparing to this SimpleBase package?

https://www.codeproject.com/tips/447938/high-performance-csharp-byte-array-to-hex-string-t?fid=1771659&df=90&mpp=50&sort=Position&view=Normal&spc=Tight&fr=1

ssg commented 6 years ago

Hi @shtse8! It might help in performance but it's hard to tell. My current encoder already employs some of the ideas there, such as reading the memory in larger chunks. My version also avoids any additional memory lookups unlike the given code. It's really hard to tell which would perform better. We need a benchmark to see if it would really help.

Personally, I'm not a fan of hard-coded lookup tables because they are harder to test and maintain. The test coverage needs to be significantly larger to ensure the whole table is correct. Simple calculation code is easier to test because you can test many of the cases with a single test case. That's not possible with hard-coded lookup tables.

Thanks for the suggestion! I might add .NET's own Base16 encoder to the benchmark suite though just to see how well we fare. I'm closing this for now, until someone comes up with a pull request :)