Skip to content

Commit

Permalink
json decoder benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
direvius committed Dec 24, 2015
1 parent ff8d45f commit 4086a09
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ammo/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ammo

import (
"bufio"
"errors"
"os"
"testing"
"time"

Expand Down Expand Up @@ -74,3 +77,23 @@ func TestHttpProvider(t *testing.T) {
t.Fatal(ctx.Err())
}
}

var result Ammo

func BenchmarkJsonDecoder(b *testing.B) {
f, err := os.Open(httpTestFilename)
if err != nil {
b.Fatal(err)
}
defer f.Close()
r := bufio.NewReader(f)
jsonDoc, isPrefix, err := r.ReadLine()
if err != nil || isPrefix {
b.Fatal(errors.New("Couldn't properly read ammo sample from data file"))
}
var a Ammo
for n := 0; n < b.N; n++ {
a, _ = HttpJSONDecode(jsonDoc)
}
result = a
}

0 comments on commit 4086a09

Please sign in to comment.