Using the EncodeToString function from the encoding/hex package is much faster than calling the fmt.Sprintf with %x Benchmark results below with the following code func BenchmarkHexPrint(b *testing.B) { data := []byte("hellothere") for n := 0; n < b.N; n++ { // _ = fmt.Sprintf("%x", data) _ = hex.EncodeToString(data) } } name old time/op new time/op delta HexPrint-4 188ns ± 1% 99ns ± 1% -47.40% (p=0.008 n=5+5) name old alloc/op new alloc/op delta HexPrint-4 64.0B ± 0% 64.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta HexPrint-4 2.00 ± 0% 2.00 ± 0% ~ (all equal)
Name |
Last commit
|
Last Update |
---|---|---|
.github | Loading commit data... | |
conf | Loading commit data... | |
docker | Loading commit data... | |
docs | Loading commit data... | |
emails | Loading commit data... | |
examples | Loading commit data... | |
packaging | Loading commit data... | |
pkg | Loading commit data... | |
public | Loading commit data... | |
scripts | Loading commit data... | |
tasks/options | Loading commit data... | |
tests | Loading commit data... | |
vendor | Loading commit data... | |
.bra.toml | Loading commit data... | |
.editorconfig | Loading commit data... | |
.gitignore | Loading commit data... | |
.jscs.json | Loading commit data... | |
.jshintrc | Loading commit data... | |
CHANGELOG.md | Loading commit data... | |
CODE_OF_CONDUCT.md | Loading commit data... | |
Gruntfile.js | Loading commit data... | |
LICENSE.md | Loading commit data... | |
Makefile | Loading commit data... | |
NOTICE.md | Loading commit data... | |
PLUGIN_DEV.md | Loading commit data... | |
README.md | Loading commit data... | |
ROADMAP.md | Loading commit data... | |
appveyor.yml | Loading commit data... | |
build.go | Loading commit data... | |
circle.yml | Loading commit data... | |
codecov.yml | Loading commit data... | |
jest.config.js | Loading commit data... | |
karma.conf.js | Loading commit data... | |
latest.json | Loading commit data... | |
package.json | Loading commit data... | |
tsconfig.json | Loading commit data... | |
tslint.json | Loading commit data... | |
yarn.lock | Loading commit data... |