displaycal-py3
displaycal-py3 copied to clipboard
Implement colormath routines in Cython?
Given the number of times colormath.specialpow
can be called and other functions in colormath, I think it would make sense to implement accelerated versions of these functions in Cython. Is this goal for displaycal-py3?
I ported specialpow to Cython and some quick benchmarks below show a nice improvement. These are called from Python, but would be even faster when called from other cython code. Porting this function took minimal effort, though it would add Cython as a dev/build dependency.
%timeit colormath.specialpow(-.05, -240)
687 ns ± 27.3 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit mycolormath.specialpow(-.05, -240)
160 ns ± 1.83 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
%timeit colormath.specialpow(-.05, -2084) # slowest path
1.23 µs ± 30.6 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit mycolormath.specialpow(-.05, -2084)
277 ns ± 4.35 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit colormath.specialpow(-.05, .03) # fastest path
364 ns ± 24 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit mycolormath.specialpow(-.05, .03)
169 ns ± 3.84 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
Hey @groutr thank you for pointing this out and your efforts on testing, I'm trying to get away from any C-Extensions, and if I don't understand your test results wrongly, what we are seeing here is a sub millisecond improvement, right?