Skip to content

Commit

Permalink
Implement benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Jan 11, 2015
1 parent 69b5fe0 commit 0bce954
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xxd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"crypto/rand"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bce954

Please sign in to comment.