Learn
Learn copied to clipboard
Numba IRR
This PR introduces a numba version of the "better" IRR implementation. It doesn't do anything other than provide the code for a new benchmark, so this PR can live until all the things are in place.
Note that in order for the numba version to work, you need to convert the cfs array to a numpy array. If you pass in the numpy array to the original "better" version, you actually get a decent speedup (1.75x) -- I think that should be reflected in these benchmarks (either switch to that version or show both). On my machine, the three Newton/"better" runs benchmark as follows:
%%timeit
irr_newton(cfs)
# 776 µs ± 8.83 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
%%timeit
irr_newton(npcfs)
# 442 µs ± 4.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
%%timeit
irr_newton_numba(npcfs)
# 30 µs ± 387 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
In short, the numba version is 26x faster than the original "better" and 15x faster than the numpy-fed "better".
A few other things to note:
- I tweaked the formatting to be a bit more consistent with Python community standards
- I refrained from too much tweaking (not sure the second
numpyandtimetitimports are necessary, cashflow arrays hardcoded in code makes it less readable) so as not to accidentally break things. - I run the
numbaversion on my own environment using Python 3.10.6 and made sure the result was the same as the "better" version. The fact that the benchmarks don't have a clear way to install an environment for someone to run is problematic IMO and should be addressed. - I'll let you run this for benchmark and reporting purposes on your machine/environment for the sake of consistency.
I'd like to open an issue or discussion to discuss improvements to these benchmarks. I know you started an issue regarding more realistic array sizes in #3 but that's only one aspect I'd like to address. Let me know if I should open a new one or if there is a specific place you want to have that discussion.
This is fine place to have the discussion - what else did you want to change?