Python Forum
Time execution of a "for loop" with zip different in 2 equivalent context
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time execution of a "for loop" with zip different in 2 equivalent context
#1
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 :)
Reply
#2
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" ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Context-sensitive delimiter ZZTurn 9 1,392 May-16-2023, 07:31 AM
Last Post: Gribouillis
  How does open context manager work? deanhystad 7 1,263 Nov-08-2022, 02:45 PM
Last Post: deanhystad
  Decimal context stevendaprano 1 1,009 Apr-11-2022, 09:44 PM
Last Post: deanhystad
  How to measure execution time of a multithread loop spacedog 2 2,835 Apr-24-2021, 07:52 AM
Last Post: spacedog
  PyCharm Script Execution Time? muzikman 3 8,354 Dec-14-2020, 11:22 PM
Last Post: muzikman
  How to to tie the execution of one process to another inside a loop in Python ignorant_wanderer 0 2,018 Jul-11-2020, 03:44 AM
Last Post: ignorant_wanderer
  Updating a matrix in a time interval inside a for loop vp1989 4 2,847 May-17-2020, 07:15 PM
Last Post: vp1989
  TextIOWrapper.tell() with Python 3.6.9 in context of 0D/0A fschaef 0 2,040 Mar-29-2020, 09:18 AM
Last Post: fschaef
  A better way to limit loop execution? t4keheart 3 2,644 Feb-26-2020, 08:24 AM
Last Post: DeaD_EyE
  Loop independent of excecution time of a script Forelli 8 3,678 Feb-02-2020, 10:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020