Skip to content

Instantly share code, notes, and snippets.

@PyYoshi PyYoshi/_.md
Last active Jul 24, 2017

Embed
What would you like to do?
blid vs rez vs gift vs imaging vs resize vs bimg

http://www-2.cs.cmu.edu/~chuck/lennapg/lena_std.tif

$ go test -bench "BenchmarkResize" -benchmem
BenchmarkResize_NfntResize_NearestNeighbor-4                	    1000	   1754846 ns/op	  845441 B/op	      24 allocs/op
BenchmarkResize_NfntResize_Bilinear-4                       	    1000	   1788142 ns/op	  847436 B/op	      24 allocs/op
BenchmarkResize_NfntResize_Bicubic-4                        	     500	   2474752 ns/op	  851532 B/op	      24 allocs/op
BenchmarkResize_NfntResize_MitchellNetravali-4              	     500	   2517930 ns/op	  851531 B/op	      24 allocs/op
BenchmarkResize_NfntResize_Lanczos2-4                       	     500	   2726255 ns/op	  851530 B/op	      24 allocs/op
BenchmarkResize_NfntResize_Lanczos3-4                       	     500	   3424438 ns/op	  855629 B/op	      24 allocs/op
BenchmarkResize_DisintegrationImaging_NearestNeighbor-4     	    1000	   1223755 ns/op	 1052979 B/op	      12 allocs/op
BenchmarkResize_DisintegrationImaging_Box-4                 	    1000	   1476005 ns/op	 1151956 B/op	     340 allocs/op
BenchmarkResize_DisintegrationImaging_Bilinear-4            	    1000	   1742245 ns/op	 1184721 B/op	     404 allocs/op
BenchmarkResize_DisintegrationImaging_Hermite-4             	    1000	   1732708 ns/op	 1184722 B/op	     404 allocs/op
BenchmarkResize_DisintegrationImaging_MitchellNetravali-4   	    1000	   2247887 ns/op	 1250258 B/op	     468 allocs/op
BenchmarkResize_DisintegrationImaging_CatmullRom-4          	     500	   2343599 ns/op	 1250256 B/op	     468 allocs/op
BenchmarkResize_DisintegrationImaging_BSpline-4             	     500	   2328418 ns/op	 1250256 B/op	     468 allocs/op
BenchmarkResize_DisintegrationImaging_Gaussian-4            	     500	   2436261 ns/op	 1250256 B/op	     468 allocs/op
BenchmarkResize_DisintegrationImaging_Bartlett-4            	     500	   3046532 ns/op	 1373145 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Lanczos3-4            	     500	   3207235 ns/op	 1373146 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Hann-4                	     500	   3076467 ns/op	 1373146 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Hamming-4             	     500	   3140182 ns/op	 1373145 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Blackman-4            	     500	   3127706 ns/op	 1373142 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Welch-4               	     500	   2996529 ns/op	 1373139 B/op	     528 allocs/op
BenchmarkResize_DisintegrationImaging_Cosine-4              	     500	   3116774 ns/op	 1373147 B/op	     528 allocs/op
BenchmarkResize_DisintegrationGift_Box-4                    	    1000	   1695010 ns/op	  818279 B/op	     488 allocs/op
BenchmarkResize_DisintegrationGift_Biinear-4                	    1000	   1874807 ns/op	  851174 B/op	     552 allocs/op
BenchmarkResize_DisintegrationGift_Bicubic-4                	    1000	   2344344 ns/op	  916997 B/op	     616 allocs/op
BenchmarkResize_DisintegrationGift_Lanczos3-4               	     500	   2874814 ns/op	 1040134 B/op	     676 allocs/op
BenchmarkResize_BamiauxRez_Bicubic-4                        	    3000	    509956 ns/op	  306306 B/op	     315 allocs/op
BenchmarkResize_BamiauxRez_Bilinear-4                       	    5000	    318861 ns/op	  186498 B/op	     315 allocs/op
BenchmarkResize_BamiauxRez_Lanczos2-4                       	    2000	    654644 ns/op	  306304 B/op	     315 allocs/op
BenchmarkResize_BamiauxRez_Lanczos3-4                       	    2000	    972404 ns/op	  426117 B/op	     315 allocs/op
BenchmarkResize_AnthonynsimonBild_NearestNeighbor-4         	    1000	   1512906 ns/op	 1052800 B/op	       4 allocs/op
BenchmarkResize_AnthonynsimonBild_Box-4                     	     500	   2461965 ns/op	 1118633 B/op	      10 allocs/op
BenchmarkResize_AnthonynsimonBild_Bilinear-4                	     500	   3200076 ns/op	 1118635 B/op	      10 allocs/op
BenchmarkResize_AnthonynsimonBild_Gaussian-4                	      50	  32731026 ns/op	 1118638 B/op	      10 allocs/op
BenchmarkResize_AnthonynsimonBild_MitchellNetravali-4       	     200	   6814239 ns/op	 1118634 B/op	      10 allocs/op
BenchmarkResize_AnthonynsimonBild_CatmullRomr-4             	     200	   6545090 ns/op	 1118638 B/op	      10 allocs/op
BenchmarkResize_AnthonynsimonBild_Lanczos3-4                	     100	  21970993 ns/op	 1118637 B/op	      10 allocs/op
$ $ go test -bench "BenchmarkDecodeAndResize" -benchmem
BenchmarkDecodeAndResize_H2nonBimg_Bicubic-4                         	     100	  12745320 ns/op	    1344 B/op	      29 allocs/op
BenchmarkDecodeAndResize_H2nonBimg_Bilinear-4                        	     100	  12953259 ns/op	    1344 B/op	      29 allocs/op
BenchmarkDecodeAndResize_H2nonBimg_Nohalo-4                          	     100	  12903898 ns/op	    1344 B/op	      29 allocs/op
BenchmarkDecodeAndResize_NfntResize_NearestNeighbor-4                	      50	  35198868 ns/op	 4796281 B/op	      41 allocs/op
BenchmarkDecodeAndResize_NfntResize_Bilinear-4                       	      50	  35253042 ns/op	 4798023 B/op	      40 allocs/op
BenchmarkDecodeAndResize_NfntResize_Bicubic-4                        	      30	  36413168 ns/op	 4802131 B/op	      40 allocs/op
BenchmarkDecodeAndResize_NfntResize_MitchellNetravali-4              	      50	  36889156 ns/op	 4802085 B/op	      40 allocs/op
BenchmarkDecodeAndResize_NfntResize_Lanczos2-4                       	      50	  36974482 ns/op	 4801920 B/op	      40 allocs/op
BenchmarkDecodeAndResize_NfntResize_Lanczos3-4                       	      50	  37492651 ns/op	 4805933 B/op	      40 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_NearestNeighbor-4     	      50	  35019467 ns/op	 5003294 B/op	      28 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Box-4                 	      50	  35583920 ns/op	 5102277 B/op	     356 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Bilinear-4            	      50	  36339601 ns/op	 5135183 B/op	     420 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Hermite-4             	      50	  35923026 ns/op	 5135035 B/op	     420 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_MitchellNetravali-4   	      30	  36370090 ns/op	 5200581 B/op	     484 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_CatmullRom-4          	      50	  36219188 ns/op	 5200567 B/op	     484 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_BSpline-4             	      50	  36440896 ns/op	 5200561 B/op	     484 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Gaussian-4            	      50	  36830426 ns/op	 5200568 B/op	     484 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Bartlett-4            	      30	  37264775 ns/op	 5323454 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Lanczos3-4            	      30	  37414380 ns/op	 5323460 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Hann-4                	      50	  37717781 ns/op	 5323438 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Hamming-4             	      30	  37593821 ns/op	 5323442 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Blackman-4            	      50	  37444063 ns/op	 5323445 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Welch-4               	      50	  37311714 ns/op	 5323436 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationImaging_Cosine-4              	      50	  37430416 ns/op	 5323447 B/op	     544 allocs/op
BenchmarkDecodeAndResize_DisintegrationGift_Box-4                    	      50	  36734399 ns/op	 4768577 B/op	     504 allocs/op
BenchmarkDecodeAndResize_DisintegrationGift_Biinear-4                	      30	  37177036 ns/op	 4801497 B/op	     568 allocs/op
BenchmarkDecodeAndResize_DisintegrationGift_Bicubic-4                	      50	  37131363 ns/op	 4867349 B/op	     632 allocs/op
BenchmarkDecodeAndResize_DisintegrationGift_Lanczos3-4               	      50	  37431459 ns/op	 4990533 B/op	     692 allocs/op
BenchmarkDecodeAndResize_BamiauxRez_Bicubic-4                        	      50	  34639023 ns/op	 4256624 B/op	     331 allocs/op
BenchmarkDecodeAndResize_BamiauxRez_Bilinear-4                       	      50	  34693049 ns/op	 4136852 B/op	     331 allocs/op
BenchmarkDecodeAndResize_BamiauxRez_Lanczos2-4                       	      30	  35036112 ns/op	 4256621 B/op	     331 allocs/op
BenchmarkDecodeAndResize_BamiauxRez_Lanczos3-4                       	      50	  35364816 ns/op	 4376454 B/op	     331 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_NearestNeighbor-4         	      50	  36016589 ns/op	 5003088 B/op	      20 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_Box-4                     	      30	  36639285 ns/op	 5068941 B/op	      26 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_Bilinear-4                	      50	  37821268 ns/op	 5068929 B/op	      26 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_Gaussian-4                	      20	  69727275 ns/op	 5068940 B/op	      26 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_MitchellNetravali-4       	      30	  41726722 ns/op	 5068946 B/op	      26 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_CatmullRomr-4             	      30	  40570739 ns/op	 5068925 B/op	      26 allocs/op
BenchmarkDecodeAndResize_AnthonynsimonBild_Lanczos3-4                	      30	  57261176 ns/op	 5068934 B/op	      26 allocs/op
$ go version
go version go1.8.3 linux/amd64
$ uname -a
Linux u1704 4.10.0-28-generic #32-Ubuntu SMP Fri Jun 30 05:32:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4690 CPU @ 3.50GHz
stepping	: 3
microcode	: 0x22
cpu MHz		: 3900.115
cache size	: 6144 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 4
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
bugs		:
bogomips	: 6997.72
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4690 CPU @ 3.50GHz
stepping	: 3
microcode	: 0x22
cpu MHz		: 3899.902
cache size	: 6144 KB
physical id	: 0
siblings	: 4
core id		: 1
cpu cores	: 4
apicid		: 2
initial apicid	: 2
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
bugs		:
bogomips	: 6997.72
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 2
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4690 CPU @ 3.50GHz
stepping	: 3
microcode	: 0x22
cpu MHz		: 3899.475
cache size	: 6144 KB
physical id	: 0
siblings	: 4
core id		: 2
cpu cores	: 4
apicid		: 4
initial apicid	: 4
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
bugs		:
bogomips	: 6997.72
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 3
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4690 CPU @ 3.50GHz
stepping	: 3
microcode	: 0x22
cpu MHz		: 3899.902
cache size	: 6144 KB
physical id	: 0
siblings	: 4
core id		: 3
cpu cores	: 4
apicid		: 6
initial apicid	: 6
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
bugs		:
bogomips	: 6997.72
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:
$ cat /proc/meminfo 
MemTotal:       16365120 kB
MemFree:          543348 kB
MemAvailable:   10865352 kB
Buffers:         4808612 kB
Cached:          5751592 kB
SwapCached:            0 kB
Active:          5471688 kB
Inactive:        9719944 kB
Active(anon):    4393484 kB
Inactive(anon):   370896 kB
Active(file):    1078204 kB
Inactive(file):  9349048 kB
Unevictable:         552 kB
Mlocked:             552 kB
SwapTotal:       2097148 kB
SwapFree:        2097092 kB
Dirty:               852 kB
Writeback:             0 kB
AnonPages:       4191712 kB
Mapped:           806184 kB
Shmem:            132956 kB
Slab:             340172 kB
SReclaimable:     231848 kB
SUnreclaim:       108324 kB
KernelStack:       18592 kB
PageTables:        84844 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    10279708 kB
Committed_AS:   15144248 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:   1290240 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:     1324896 kB
DirectMap2M:    15386624 kB
DirectMap1G:           0 kB
package benchmarks
import (
"image"
_ "image/jpeg"
"io"
"testing"
"github.com/anthonynsimon/bild/transform"
"github.com/bamiaux/rez"
"github.com/disintegration/gift"
"github.com/disintegration/imaging"
"github.com/nfnt/resize"
bimg "gopkg.in/h2non/bimg.v1"
)
//////////////////////////////////// gopkg.in/h2non/bimg.v1
func BenchmarkDecodeAndResize_H2nonBimg_Bicubic(b *testing.B) {
options := bimg.Options{
Width: 32,
Height: 32,
Embed: true,
Interpolator: bimg.Bicubic,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
img := bimg.NewImage(testResizeJpgRaw)
img.Process(options)
}
}
func BenchmarkDecodeAndResize_H2nonBimg_Bilinear(b *testing.B) {
options := bimg.Options{
Width: 32,
Height: 32,
Embed: true,
Interpolator: bimg.Bilinear,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
img := bimg.NewImage(testResizeJpgRaw)
img.Process(options)
}
}
func BenchmarkDecodeAndResize_H2nonBimg_Nohalo(b *testing.B) {
options := bimg.Options{
Width: 32,
Height: 32,
Embed: true,
Interpolator: bimg.Nohalo,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
img := bimg.NewImage(testResizeJpgRaw)
img.Process(options)
}
}
//////////////////////////////////// github.com/nfnt/resize
func BenchmarkDecodeAndResize_NfntResize_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.NearestNeighbor)
}
}
func BenchmarkDecodeAndResize_NfntResize_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.Bilinear)
}
}
func BenchmarkDecodeAndResize_NfntResize_Bicubic(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.Bicubic)
}
}
func BenchmarkDecodeAndResize_NfntResize_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.MitchellNetravali)
}
}
func BenchmarkDecodeAndResize_NfntResize_Lanczos2(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.Lanczos2)
}
}
func BenchmarkDecodeAndResize_NfntResize_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
resize.Resize(32, 32, img, resize.Lanczos3)
}
}
//////////////////////////////////// github.com/disintegration/imaging
func BenchmarkDecodeAndResize_DisintegrationImaging_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.NearestNeighbor)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Box(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Box)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Linear)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Hermite(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Hermite)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.MitchellNetravali)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_CatmullRom(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.CatmullRom)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_BSpline(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.BSpline)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Gaussian(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Gaussian)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Bartlett(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Bartlett)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Lanczos)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Hann(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Hann)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Hamming(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Hamming)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Blackman(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Blackman)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Welch(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Welch)
}
}
func BenchmarkDecodeAndResize_DisintegrationImaging_Cosine(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
imaging.Resize(img, 32, 32, imaging.Cosine)
}
}
//////////////////////////////////// github.com/disintegration/gift
// func BenchmarkDecodeAndResize_DisintegrationGift_NearestNeighbor(b *testing.B) {
// g := gift.New(
// gift.Resize(32, 32, gift.NearestNeighborResampling),
// )
// dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
// b.ResetTimer()
// for i := 0; i < b.N; i++ {
// testResizeJpgBytesReader.Seek(0, io.SeekStart)
// img, _, _ := image.Decode(testResizeJpgBytesReader)
// g.Draw(dst, img)
// }
// }
func BenchmarkDecodeAndResize_DisintegrationGift_Box(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.BoxResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
g.Draw(dst, img)
}
}
func BenchmarkDecodeAndResize_DisintegrationGift_Biinear(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.LinearResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
g.Draw(dst, img)
}
}
func BenchmarkDecodeAndResize_DisintegrationGift_Bicubic(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.CubicResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
g.Draw(dst, img)
}
}
func BenchmarkDecodeAndResize_DisintegrationGift_Lanczos3(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.LanczosResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
g.Draw(dst, img)
}
}
//////////////////////////////////// github.com/bamiaux/rez
func BenchmarkDecodeAndResize_BamiauxRez_Bicubic(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewBicubicFilter()
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
rez.Convert(dst, img, f)
}
}
func BenchmarkDecodeAndResize_BamiauxRez_Bilinear(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewBilinearFilter()
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
rez.Convert(dst, img, f)
}
}
func BenchmarkDecodeAndResize_BamiauxRez_Lanczos2(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewLanczosFilter(2.0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
rez.Convert(dst, img, f)
}
}
func BenchmarkDecodeAndResize_BamiauxRez_Lanczos3(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewLanczosFilter(3.0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
rez.Convert(dst, img, f)
}
}
//////////////////////////////////// github.com/anthonynsimon/bild
func BenchmarkDecodeAndResize_AnthonynsimonBild_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.NearestNeighbor)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_Box(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.Box)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.Linear)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_Gaussian(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.Gaussian)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.MitchellNetravali)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_CatmullRomr(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.CatmullRom)
}
}
func BenchmarkDecodeAndResize_AnthonynsimonBild_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
testResizeJpgBytesReader.Seek(0, io.SeekStart)
img, _, _ := image.Decode(testResizeJpgBytesReader)
transform.Resize(img, 32, 32, transform.Lanczos)
}
}
package benchmarks
import (
"bytes"
"image"
"io"
"io/ioutil"
"log"
"testing"
"github.com/anthonynsimon/bild/transform"
"github.com/bamiaux/rez"
"github.com/disintegration/gift"
"github.com/disintegration/imaging"
"github.com/nfnt/resize"
)
var (
testResizeJpgRaw []byte
testResizeJpegImage image.Image
testResizeJpgBytesReader *bytes.Reader
)
func init() {
raw, err := ioutil.ReadFile("../testdata/lena_std.jpg")
if err != nil {
log.Fatal(err)
}
// Copy
testResizeJpgRaw = raw
testResizeJpgBytesReader = bytes.NewReader(raw)
testResizeJpegImage, _, _ = image.Decode(testResizeJpgBytesReader)
testResizeJpgBytesReader.Seek(0, io.SeekStart)
}
//////////////////////////////////// github.com/nfnt/resize
func BenchmarkResize_NfntResize_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.NearestNeighbor)
}
}
func BenchmarkResize_NfntResize_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.Bilinear)
}
}
func BenchmarkResize_NfntResize_Bicubic(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.Bicubic)
}
}
func BenchmarkResize_NfntResize_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.MitchellNetravali)
}
}
func BenchmarkResize_NfntResize_Lanczos2(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.Lanczos2)
}
}
func BenchmarkResize_NfntResize_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
resize.Resize(32, 32, testResizeJpegImage, resize.Lanczos3)
}
}
//////////////////////////////////// github.com/disintegration/imaging
func BenchmarkResize_DisintegrationImaging_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.NearestNeighbor)
}
}
func BenchmarkResize_DisintegrationImaging_Box(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Box)
}
}
func BenchmarkResize_DisintegrationImaging_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Linear)
}
}
func BenchmarkResize_DisintegrationImaging_Hermite(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Hermite)
}
}
func BenchmarkResize_DisintegrationImaging_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.MitchellNetravali)
}
}
func BenchmarkResize_DisintegrationImaging_CatmullRom(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.CatmullRom)
}
}
func BenchmarkResize_DisintegrationImaging_BSpline(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.BSpline)
}
}
func BenchmarkResize_DisintegrationImaging_Gaussian(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Gaussian)
}
}
func BenchmarkResize_DisintegrationImaging_Bartlett(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Bartlett)
}
}
func BenchmarkResize_DisintegrationImaging_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Lanczos)
}
}
func BenchmarkResize_DisintegrationImaging_Hann(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Hann)
}
}
func BenchmarkResize_DisintegrationImaging_Hamming(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Hamming)
}
}
func BenchmarkResize_DisintegrationImaging_Blackman(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Blackman)
}
}
func BenchmarkResize_DisintegrationImaging_Welch(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Welch)
}
}
func BenchmarkResize_DisintegrationImaging_Cosine(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
imaging.Resize(testResizeJpegImage, 32, 32, imaging.Cosine)
}
}
//////////////////////////////////// github.com/disintegration/gift
// func BenchmarkResize_DisintegrationGift_NearestNeighbor(b *testing.B) {
// g := gift.New(
// gift.Resize(32, 32, gift.NearestNeighborResampling),
// )
// dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
// b.ResetTimer()
// for i := 0; i < b.N; i++ {
// g.Draw(dst, testResizeJpegImage)
// }
// }
func BenchmarkResize_DisintegrationGift_Box(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.BoxResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.Draw(dst, testResizeJpegImage)
}
}
func BenchmarkResize_DisintegrationGift_Biinear(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.LinearResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.Draw(dst, testResizeJpegImage)
}
}
func BenchmarkResize_DisintegrationGift_Bicubic(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.CubicResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.Draw(dst, testResizeJpegImage)
}
}
func BenchmarkResize_DisintegrationGift_Lanczos3(b *testing.B) {
g := gift.New(
gift.Resize(32, 32, gift.LanczosResampling),
)
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
b.ResetTimer()
for i := 0; i < b.N; i++ {
g.Draw(dst, testResizeJpegImage)
}
}
//////////////////////////////////// github.com/bamiaux/rez
func BenchmarkResize_BamiauxRez_Bicubic(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewBicubicFilter()
b.ResetTimer()
for i := 0; i < b.N; i++ {
rez.Convert(dst, testResizeJpegImage, f)
}
}
func BenchmarkResize_BamiauxRez_Bilinear(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewBilinearFilter()
b.ResetTimer()
for i := 0; i < b.N; i++ {
rez.Convert(dst, testResizeJpegImage, f)
}
}
func BenchmarkResize_BamiauxRez_Lanczos2(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewLanczosFilter(2.0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rez.Convert(dst, testResizeJpegImage, f)
}
}
func BenchmarkResize_BamiauxRez_Lanczos3(b *testing.B) {
dst := image.NewYCbCr(image.Rect(0, 0, 32, 32), image.YCbCrSubsampleRatio444)
f := rez.NewLanczosFilter(3.0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rez.Convert(dst, testResizeJpegImage, f)
}
}
//////////////////////////////////// github.com/anthonynsimon/bild
func BenchmarkResize_AnthonynsimonBild_NearestNeighbor(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.NearestNeighbor)
}
}
func BenchmarkResize_AnthonynsimonBild_Box(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.Box)
}
}
func BenchmarkResize_AnthonynsimonBild_Bilinear(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.Linear)
}
}
func BenchmarkResize_AnthonynsimonBild_Gaussian(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.Gaussian)
}
}
func BenchmarkResize_AnthonynsimonBild_MitchellNetravali(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.MitchellNetravali)
}
}
func BenchmarkResize_AnthonynsimonBild_CatmullRomr(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.CatmullRom)
}
}
func BenchmarkResize_AnthonynsimonBild_Lanczos3(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
transform.Resize(testResizeJpegImage, 32, 32, transform.Lanczos)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.