I wrote some python code to scrap ranking data from a site. I have several pages to check which are the same for different periods (1, 2, 5 and 10 years), at the end of my code, I called every function in an if name.
At first I had this:
scrapBase1(year)
scrapBase2(year)
scrapBase5(year)
scrapBase10(year)
scrapBaseLong1(year)
scrapBaseLong2(year)
scrapBaseLong5(year)
scrapBaseLong10(year)
I made several changes in the overall code but also in the way I'm calling those functions:
for duration in [1, 2, 5, 10]:
scrapBase(year, duration)
for duration in [1, 2, 5, 10]:
scrapLong(year, duration)
The code is better now but also much slower which is not much of an issue but I was wondering if this new way of calling made any difference?(and is it the best way to make the calls?) Would it be possible to have an explanation about why for loop would be faster or slower than calling the functions one by one?
Transmission data over network is much slower than simple CPU calculations. Calling functions in cycles in your case is not a problem, there's some other issue in your code.