muesli / smartcrop

smartcrop finds good image crops for arbitrary crop sizes
MIT License
1.82k stars 114 forks source link

Use normal multiplication instead of exponentiaion for pow 2 case. #9

Closed danhper closed 10 years ago

danhper commented 10 years ago

math.Pow is quite heavy and wastes a lot of time while computing the score. Replacing it by a simple multiplication reduces time by almost 2.

These are the results I got to convert a 598x900 to a 250x250 pixels image with an i7 processor.

With math.Pow:

$ ./foo 
0.46451133407655143
original resolution: 598x900
scale: 2.392000, cropw: 277.000000, croph: 277.000000, minscale: 0.900000
Time elapsed edge: 48.715635ms
Time elapsed skin: 69.20784ms
Time elapsed sat: 29.168815ms
Time elapsed crops: 57.868us 102
Time elapsed score: 2.086053949s

With x * x:

$ ./foo 
0.46451133407655143
original resolution: 598x900
scale: 2.392000, cropw: 277.000000, croph: 277.000000, minscale: 0.900000
Time elapsed edge: 47.328424ms
Time elapsed skin: 32.094467ms
Time elapsed sat: 29.98ms
Time elapsed crops: 52.197us 102
Time elapsed score: 1.051735309s
muesli commented 10 years ago

Thanks for the improvement! Nice find! I'm now actually trying to get this improvement for math.Pow(x, 2) upstream.