nfnt / resize

Pure golang image resizing
ISC License
3.02k stars 321 forks source link

Optimize bound checks and limit goroutines to GOMAXPROCS(0). #28

Closed charlievieth closed 9 years ago

charlievieth commented 9 years ago

Optimizing the conversion function bound checks increased overall performance by 14.8%. The benchmarks were also updated to better reflect conversion performance.

Also, runtime.GOMAXPROCS(0) is used instead of runtime.NumCPU() to determine the number of spawned goroutines. This allows clients to limit the number of spawned goroutines, and slightly increases performance.

Test Results

go test -cpu 1 -bench .
Test Previous Updated Change
Benchmark_Nearest_RGBA 3588122 3079371 16.5%
Benchmark_Bilinear_RGBA 5719682 4835984 18.3%
Benchmark_Bicubic_RGBA 7914568 6702097 18.1%
Benchmark_Mitchell_RGBA 8866317 8063793 10.0%
Benchmark_Lanczos2_RGBA 8049316 6853025 17.5%
Benchmark_Lanczos3_RGBA 10525981 8845505 19.0%
Benchmark_Nearest_YCC 4120125 3766400 9.4%
Benchmark_Bilinear_YCC 5673952 5048623 12.4%
Benchmark_Bicubic_YCC 7646177 6699744 14.1%
Benchmark_Mitchell_YCC 8558137 7531485 13.6%
Benchmark_Lanczos2_YCC 7738619 6814587 13.6%
Benchmark_Lanczos3_YCC 9711631 8500676 14.2%
Total 14.8%
nfnt commented 9 years ago

Thank you!