radbelt icon indicating copy to clipboard operation
radbelt copied to clipboard

Refactored version and efficiency

Open jacobwilliams opened this issue 4 months ago • 4 comments

FYI

I've refactored the Fortran code to modern standards, and you can find it here if you are interested: https://github.com/jacobwilliams/radbelt

Your Python version is very inefficient, I believe because it is reading all the data files every time the get_flux function is called? Unless I'm reading it wrong or calling it incorrectly. See my test case.

Compare to my refactored version:

Python version runtime:           3.514 sec.     409 (cases/sec) <-- reading the files every time
Fortran Function version runtime: 1.622 sec.    1198 (cases/sec) <-- reading the files every time
Fortran Class version runtime:    0.017 sec.  112259 (cases/sec) <-- caching the data from the files

The class version of mine will only read the files once, and store the data in the class so that subsequent calls don't have to read it again. That results in a huge speedup. Something like that could be implemented for the Python wrapper I believe.

jacobwilliams avatar Feb 10 '24 16:02 jacobwilliams