// BenchmarkEncoder is a helper to benchmark Encoder. func BenchmarkEncoder(b *testing.B, enc imageserver_image.Encoder, im *imageserver.Image, params imageserver.Params) { nim, err := imageserver_image.Decode(im) if err != nil { b.Fatal(err) } b.ResetTimer() for i := 0; i < b.N; i++ { err := enc.Encode(ioutil.Discard, nim, params) if err != nil { b.Fatal(err) } } }
// TestEncoderParams is a helper to test Encoder with Params. func TestEncoderParams(t *testing.T, enc imageserver_image.Encoder, params imageserver.Params, expectedFormat string) { buf := new(bytes.Buffer) nim := NewImage() err := enc.Encode(buf, nim, params) if err != nil { t.Fatal(err) } _, format, err := image.Decode(buf) if err != nil { t.Fatal(err) } if format != expectedFormat { t.Fatalf("unexpected format: got %s, want %s", format, expectedFormat) } }
// BenchmarkEncoder is a helper to benchmark Encoder. func BenchmarkEncoder(b *testing.B, enc imageserver_image.Encoder, im *imageserver.Image, params imageserver.Params) { nim, err := imageserver_image.Decode(im) if err != nil { b.Fatal(err) } b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { err := enc.Encode(ioutil.Discard, nim, params) if err != nil { b.Fatal(err) } } }) }