Python Forum
Time execution of a "for loop" with zip different in 2 equivalent context - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Time execution of a "for loop" with zip different in 2 equivalent context (/thread-21695.html)



Time execution of a "for loop" with zip different in 2 equivalent context - sebastien - Oct-10-2019

Hi everybody,

I am using this portion of code with a "for loop" and zip in two different but rather equivalent context :

result = multiproc_map(local_analysis, state_batches)
for ii, (ATii,muii) in zip(state_batches, result):
   AT[:,ii] = ATii 
   mu[ii]  = muii
In each case the shape local_analysis is the same function and state_batches, ii, ATII and muii are the same and have the same shape but the time of execution in seconds of multiproc_map and the "for loop" is really different in the 2 cases :

Quote: Time of execution of multiproc_map : 9.5367431640625e-07 4.069389343261719

Time of execution of the "for loop": 13.779568910598755 0.0259706974029541

I write this script on top of the DAPPER package so I do not expect you to reproduce the case, nor to solve it, just giving me ways to understand why these results can be so different.

Any help would be highly appreciated :)


RE: Time execution of a "for loop" with zip different in 2 equivalent context - sebastien - Oct-11-2019

So, as I was using this loop in two different cases, I could trace the origin of the bug. I finally found that there was a difference in the time execution of the "for loop" if I change the position of the parameters in the definition of the function and use keywords arguments. Here is the old definition of the function:

def hybrid_dual_resolution(N,Nl,Nhs,Nls,alpha,betaH1,betaH2,betaH3,betaL1,betaL2,betaL3,
                           opt_file_hr,opt_file_lr,loc_radh,loc_radl,upd_a,
                           infl=1.0,rot=False,mp=False,taper='GC',**kwargs):
Here is the new definition of the function where I give the arguments as keywords arguments:

def hybrid_dual_resolution(opt_file_hr=None,opt_file_lr=None,upd_a='DEnKF',
                           N=3,Nhs=200,Nl=32,Nls=200,loc_radh=17.7,loc_radl=8.75,
                           alpha=0.04,
                           betaH1=1.,betaH2=0.,betaH3=0.,
                           betaL1=0.,betaL2=1.,betaL3=0.,
                           taper='GC',infl=1.0,
                           rot=False,mp=False,**kwargs):
And now the time of execution of the loop is the same in both cases and close to the minimum time I mentioned in the previous post.

I am quite surprised by this bug. Do you think that passing the arguments as keywords arguments can change the execution time of the "for loop" ?