# Re: [Tutor] Finding Match in nexted tuple

Magnus Lycka magnus at thinkware.se
Thu Apr 22 06:08:42 EDT 2004

```Tim Johnson wrote:
> > if '85004' in str(zip_code_list):
> >     print "Found!"
>
>   Eureka! That's what I meant by a 'pythonesque' solution.
>
>   I must ask: what is the overhead in the call to str?

That obviously depends on the size of your tuple... You
don't really need to ask, sincce it's so easy to measure.

>>> import time
>>> t = tuple(range(10000))
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
0.0117802648716
>>> print (stop-start)/len(s)
2.00038459358e-007
>>> t = tuple(range(100000))
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
0.129701084998
>>> print (stop-start)/len(s)
1.88275464875e-007
>>> t = tuple(range(1000000))
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
1.45181707401
>>> print (stop-start)/len(s)
1.84033124306e-007

About 0.2 microseconds per character in the string on a
machine which benchmarks at 24469.9 pystones/second. :)

But these aren't nested tuples. Does that make a difference?

>>> t = tuple([(x,) for x in range(10000)])
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
0.0236703202027
>>> print (stop-start)/len(s)
2.66287773683e-007
>>> t = tuple([(x,) for x in range(100000)])
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
0.245343962614
>>> print (stop-start)/len(s)
2.48100357587e-007
>>> t = tuple([(x,) for x in range(1000000)])
>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
2.9241021068
>>> print (stop-start)/len(s)
2.68539961998e-007

It grew? Let's try once more.

>>> start=time.clock();s=str(t);stop=time.clock()
>>> print stop-start
2.66894405045
>>> print (stop-start)/len(s)
2.45107081663e-007

So, it seems we end up at 0.25 microseconds per character in the
resulting string for your type of nested tuple.

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se

```