time consuming loops over lists

Andrea Griffini agriff at tin.it
Tue Jun 7 17:02:36 EDT 2005


On Tue, 07 Jun 2005 18:13:01 +0200, "Diez B. Roggisch" <deets at web.de>
wrote:

>Another optimization im too lazy now would be to do sort of a "tree 
>search" of data[i] in rngs - as the ranges are ordered, you could find 
>the proper one in log_2(len(rngs)) instead of len(rngs)/2.

I don't see a "break" so why the "/2" ? also IIUC the
ranges are more than just ordered... they're all equal
and computed by

     for i in xrange(no_of_bins+1):
          rngs[i] = dmin + (rng*i)

so my guess is that instead of searching with

          for j in xrange(len(rngs)-1):
               if rngs[j] <= data[i] < rngs[j+1]:

one could just do

	j = int((data[i] - dmin)/rng)

The code with this change gets roughly about twice faster.

Andrea



More information about the Python-list mailing list