Use cases for del

George Sakkis gsakkis at rutgers.edu
Fri Jul 8 14:27:07 CEST 2005


"Ron Adam" <rrr at ronadam.com> wrote:

> Here's something interesting:
>
> import time
>
> x = None
> t = time.time()
> for i in range(1000000):
>      if x==None:
>          pass
> print 'None:',time.time()-t
>
> x = 'to-end'
> t = time.time()
> for i in range(1000000):
>      if x=='to-end':
>          pass
> print 'String:',time.time()-t
>
>  >>>
> None: 0.46799993515
> String: 0.360000133514
>
>
> Of course the difference this would make on a single call in practically
> Nill.
>

How about using the right way of comparing with None ?

x = None
t = time.time()
for i in range(1000000):
      if x is None:
          pass
print 'is None:',time.time()-t

I get:

None: 0.549999952316
String: 0.498000144958
is None: 0.450000047684

> Anyway, time to call it a night so tomorrow I don't make anymore silly
> mistakes on comp.lang.python. :)

That would be a great idea ;-) An even greater idea would be to give up
on this "None should mean undefined" babble; it looks like a solution
looking for a problem and it raises more complications than it actually
solves (assuming it does actually solve anything, which is not quite
obvious).

> Cheers,
> Ron

Cheers,
George




More information about the Python-list mailing list