From 0bce954073ce92b72ed3fbcf36603c6e23852feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 11 Jan 2015 16:33:42 +0100 Subject: [PATCH] Implement benchmark --- xxd_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xxd_test.go b/xxd_test.go index a498e22..a437f4f 100644 --- a/xxd_test.go +++ b/xxd_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "crypto/rand" "flag" "fmt" "io" @@ -47,6 +48,19 @@ func TestXXD(t *testing.T) { } } +func BenchmarkXXD(b *testing.B) { + b.StopTimer() + data := make([]byte, b.N) + if _, err := io.ReadFull(rand.Reader, data); err != nil { + b.Fatal(err) + } + buf := bytes.NewBuffer(data) + b.StartTimer() + if err := XXD(buf, ioutil.Discard); err != nil { + b.Fatal(err) + } +} + func xxdNative(r io.Reader, w io.Writer) error { xxd := exec.Command("xxd", "-") xxd.Stdin = r