Created
May 20, 2019 03:12
-
-
Save pgaskin/433da6708531ec700d74d2deb6f47add to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package imgbench | |
| // Compile (or use GOARCH=arm for cross) with: go test -c | |
| // Run with: ./imgbench.test -test.bench=. | |
| import ( | |
| "image" | |
| "image/jpeg" | |
| "os" | |
| "testing" | |
| "github.com/anthonynsimon/bild/transform" | |
| "github.com/bamiaux/rez" | |
| "github.com/disintegration/imaging" | |
| "github.com/nfnt/resize" | |
| ) | |
| const w, h = 160, 200 | |
| var img image.Image | |
| func init() { | |
| // TODO: maybe try different images for fairness? | |
| f, err := os.Open("cover.jpg") | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer f.Close() | |
| img, err = jpeg.Decode(f) | |
| if err != nil { | |
| panic(err) | |
| } | |
| } | |
| func BenchmarkImagingLanczos(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = imaging.Resize(img, w, h, imaging.Lanczos) | |
| } | |
| } | |
| func BenchmarkImagingNearestNeighbor(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = imaging.Resize(img, w, h, imaging.NearestNeighbor) | |
| } | |
| } | |
| func BenchmarkImagingCatmullRom(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = imaging.Resize(img, w, h, imaging.CatmullRom) | |
| } | |
| } | |
| func BenchmarkImagingMitchellNetravali(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = imaging.Resize(img, w, h, imaging.MitchellNetravali) | |
| } | |
| } | |
| func BenchmarkImagingLinear(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = imaging.Resize(img, w, h, imaging.Linear) | |
| } | |
| } | |
| func BenchmarkResizeNearestNeighbor(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.NearestNeighbor) | |
| } | |
| } | |
| func BenchmarkResizeBilinear(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.Bilinear) | |
| } | |
| } | |
| func BenchmarkResizeBicubic(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.Bicubic) | |
| } | |
| } | |
| func BenchmarkResizeLanczos2(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.Lanczos2) | |
| } | |
| } | |
| func BenchmarkResizeLanczos3(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.Lanczos3) | |
| } | |
| } | |
| func BenchmarkResizeMitchellNetravali(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = resize.Resize(w, h, img, resize.MitchellNetravali) | |
| } | |
| } | |
| /*hopelessly slow: func BenchmarkCaire(b *testing.B) { | |
| nimg := image.NewNRGBA(img.Bounds()) | |
| draw.Draw(nimg, img.Bounds(), img, image.Pt(0, 0), draw.Over) | |
| for n := 0; n < b.N; n++ { | |
| _, _ = (&caire.Processor{ | |
| NewWidth: w, | |
| NewHeight: h, | |
| }).Resize(nimg) | |
| } | |
| }*/ | |
| func BenchmarkBildLinear(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.Linear) | |
| } | |
| } | |
| func BenchmarkBildBox(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.Box) | |
| } | |
| } | |
| func BenchmarkBildGaussian(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.Gaussian) | |
| } | |
| } | |
| func BenchmarkBildMitchellNetravali(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.MitchellNetravali) | |
| } | |
| } | |
| func BenchmarkBildCatmullRom(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.CatmullRom) | |
| } | |
| } | |
| func BenchmarkBildLanczos(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| _ = transform.Resize(img, w, h, transform.Lanczos) | |
| } | |
| } | |
| func BenchmarkRezBicubic(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| nimg := image.NewYCbCr(image.Rect(0, 0, w, h), img.(*image.YCbCr).SubsampleRatio) | |
| _ = rez.Convert(nimg, img, rez.NewBicubicFilter()) | |
| } | |
| } | |
| func BenchmarkRezBilinear(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| nimg := image.NewYCbCr(image.Rect(0, 0, w, h), img.(*image.YCbCr).SubsampleRatio) | |
| _ = rez.Convert(nimg, img, rez.NewBilinearFilter()) | |
| } | |
| } | |
| func BenchmarkRezLanczos2(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| nimg := image.NewYCbCr(image.Rect(0, 0, w, h), img.(*image.YCbCr).SubsampleRatio) | |
| _ = rez.Convert(nimg, img, rez.NewLanczosFilter(2)) | |
| } | |
| } | |
| func BenchmarkRezLanczos3(b *testing.B) { | |
| for n := 0; n < b.N; n++ { | |
| nimg := image.NewYCbCr(image.Rect(0, 0, w, h), img.(*image.YCbCr).SubsampleRatio) | |
| _ = rez.Convert(nimg, img, rez.NewLanczosFilter(3)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment