Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Fredrik Lundh
Steve Holden wrote:

 And statements like that are probably going to annoy me ;-)

   t = timeit.Timer(b = map(lambda x: x-1, a), setup=a=[1,2,3])
   t.timeit()
 2.4686168214116599
   t = timeit.Timer(b = [x-1 for x in a], setup=a=[1,2,3])
   t.timeit()
 0.9930245324475635
  

And now someone's probably reading this and thinking that list comprehensions
are *always* faster than map...

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Steve Holden
Fredrik Lundh wrote:
 Steve Holden wrote:
 
 
And statements like that are probably going to annoy me ;-)

  t = timeit.Timer(b = map(lambda x: x-1, a), setup=a=[1,2,3])
  t.timeit()
2.4686168214116599
  t = timeit.Timer(b = [x-1 for x in a], setup=a=[1,2,3])
  t.timeit()
0.9930245324475635
 
 
 
 And now someone's probably reading this and thinking that list comprehensions
 are *always* faster than map...
 
You are so right. So, let me repeat the important part that Fredrik 
didn't quote:

if performance is *really* important, you
need to benchmark both options

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Ant

Steve Holden wrote:
 Fredrik Lundh wrote:
  Steve Holden wrote:
 
...
 if performance is *really* important, you
 need to benchmark both options

Fair point.

-- 
http://mail.python.org/mailman/listinfo/python-list