From dce3bca200ae499e1cf57994c7592a42f66694d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 11 Jan 2015 16:55:26 +0100 Subject: [PATCH] optimize: remove printf for hex encoding ~208 ns/op now --- xxd.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xxd.go b/xxd.go index 1d8ad24..d9e17f8 100644 --- a/xxd.go +++ b/xxd.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "encoding/hex" "fmt" "io" "os" @@ -48,7 +49,7 @@ func XXD(r io.Reader, w io.Writer) error { // Hex values for i := 0; i < n; i++ { - fmt.Fprintf(w, "%02x", buf[i]) + io.WriteString(w, hex.EncodeToString(buf[i:i+1])) if i%2 == 1 { io.WriteString(w, " ")