Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numba IRR #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DimitarVanguelov
Copy link
Contributor

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 numpy and timetit imports are necessary, cashflow arrays hardcoded in code makes it less readable) so as not to accidentally break things.
  • I run the numba version 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.

@alecloudenback
Copy link
Member

This is fine place to have the discussion - what else did you want to change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants