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.