Instead of rewriting critical sections of your code, consider running the code on a machine with a faster processor, more cores, more RAM memory, faster bus speeds, and/or reduced disk latency. This suggestion may seem like a glib cop-out, but it's not. Sure, using a bigger machine for your analytics sometimes means extra money, but your time, dear reader, is money too. If, over the course of your work, it takes you many hours to optimize your code adequately, buying or renting a better machine may actually prove to be the more cost-effective solution.
Going down this road needn't require that you purchase a high-powered machine outrightly; there are now virtual servers that you can rent online for finite periods of time at reasonable prices. Some of these virtual servers can be configured to have 2 terabytes of RAM and 40 virtual processors. If you are interested in learning more on this option, look at the offerings of Digital Ocean, Amazon Elastic Compute Cloud, or many other similar service providers.
Ask your employer or research advisor if this is a feasible option. If you are working for a non-profit with a limited budget, you may be able to work out a deal with a particularly charitable cloud computing service provider. Tell 'em that 'Tony' sent you! But don't actually do that.
3.142.245.44