anthonynsimon / bild

Image processing algorithms in pure Go
MIT License
3.99k stars 213 forks source link

Optimize transform #21

Closed anthonynsimon closed 8 years ago

anthonynsimon commented 8 years ago

I optimized the Rotate function for special angles (for ex.: 90, 180, 270...), as these angles don't need supersampling when rotating. Now it performs much faster.

benchmark                   old ns/op      new ns/op      delta
BenchmarkRotation256-8      7858767        876950         -88.84%
BenchmarkRotation512-8      29263657       4050521        -86.16%
BenchmarkRotation1024-8     119374673      15880952       -86.70%
BenchmarkRotation2048-8     466060630      89323900       -80.83%
BenchmarkRotation4096-8     2033882420     388791904      -80.88%
BenchmarkRotation8192-8     8476689250     1663045960     -80.38%

benchmark                   old allocs     new allocs     delta
BenchmarkRotation256-8      21             7              -66.67%
BenchmarkRotation512-8      21             7              -66.67%
BenchmarkRotation1024-8     21             7              -66.67%
BenchmarkRotation2048-8     21             7              -66.67%
BenchmarkRotation4096-8     21             7              -66.67%
BenchmarkRotation8192-8     21             7              -66.67%

benchmark                   old bytes      new bytes     delta
BenchmarkRotation256-8      4457292        524540        -88.23%
BenchmarkRotation512-8      17826589       2097424       -88.23%
BenchmarkRotation1024-8     71303960       8388876       -88.24%
BenchmarkRotation2048-8     285213464      33554698      -88.24%
BenchmarkRotation4096-8     1140851480     134218001     -88.24%
BenchmarkRotation8192-8     4563403544     536871168     -88.24%

Also partly optimized the Resize function which is part of how supersampling is handled, so non-special angles should see a small performance increase. More optimizations should be made on that.

This closes #20