Skip to content

Commit

Permalink
frame: Fix Frame.Parse benchmark and add Frame.Hash benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Feb 11, 2016
1 parent e64cfef commit d675e0a
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions frame/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,55 @@ func BenchmarkFrameParse(b *testing.B) {
// in the repository, but is available for download at
//
// http://freesound.org/people/jarfil/sounds/151185/
stream, err := flac.Open("../testdata/benchmark/151185.flac")
if err != nil {
b.Fatal(err)
}
for i := 0; i < b.N; i++ {
_, err := stream.ParseNext()
stream, err := flac.Open("../testdata/benchmark/151185.flac")
if err != nil {
if err == io.EOF {
break
b.Fatal(err)
}
for {
_, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
break
}
stream.Close()
b.Fatal(err)
}
}
stream.Close()
}
}

func BenchmarkFrameHash(b *testing.B) {
// The file 151185.flac is a 119.5 MB public domain FLAC file used to
// benchmark the flac library. Because of its size, it has not been included
// in the repository, but is available for download at
//
// http://freesound.org/people/jarfil/sounds/151185/
for i := 0; i < b.N; i++ {
stream, err := flac.Open("../testdata/benchmark/151185.flac")
if err != nil {
b.Fatal(err)
}
md5sum := md5.New()
for {
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
break
}
stream.Close()
b.Fatal(err)
}
frame.Hash(md5sum)
}
stream.Close()
want := stream.Info.MD5sum[:]
got := md5sum.Sum(nil)
// Verify the decoded audio samples by comparing the MD5 checksum that is
// stored in StreamInfo with the computed one.
if !bytes.Equal(got, want) {
b.Fatalf("MD5 checksum mismatch for decoded audio samples; expected %32x, got %32x", want, got)
}
}
}

0 comments on commit d675e0a

Please sign in to comment.