<br><br><div class="gmail_quote">On Thu, Oct 23, 2008 at 2:03 PM, Jani Tiainen <span dir="ltr"><<a href="mailto:redetin@gmail.com">redetin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have rather simple 'Address' object that contains streetname,<br>
number, my own status and x,y coordinates for it. I have two lists<br>
both containing approximately 30000 addresses.<br>
<br>
I've defined __eq__ method in my class like this:<br>
<br>
def __eq__(self, other):<br>
return self.xcoord == other.xcoord and \<br>
self.ycoord == other.ycoord and \<br>
self.streetname == other.streetname and \<br>
self.streetno == other.streetno<br>
<br>
But it turns out to be very, very slow.<br>
<br>
Then I setup two lists:<br>
<br>
list_external = getexternal()<br>
list_internal = getinternal()<br>
<br>
Now I need get all all addresses from 'list_external' that are not in<br>
'list_internal', and mark them as "new".<br>
<br>
I did it like this:<br>
<br>
for addr in list_external:<br>
if addr not in list_internal:<br>
addr.status = 1 # New address<br>
<br>
But in my case running that loop takes about 10 minutes. What I am<br>
doing wrong?<br>
</blockquote><div>Sorry I don't see what you're doing wrong,<br>except I'lde write "if not ( addr in list internal) :"<br><br>but you might consider using dictionaries.<br>A couple of days ago I did some speed comparison between C and Python.<br>
We used the lookup of a string in a hash table (= dictionary in Python),<br>the results were amazing:<br>Search string was between 50 and 100 characters.<br>The table / dictionary was build with 10 million strings, each also 50 .. 100 characters long.<br>
We repeated the search 100 million times and measured the time.<br><br>Code length:<br>C, about 150 lines of unreadable code<br>Python: about 20 lines of very easy to read code lines<br><br>Development time<br>C : 1.5 days<br>
Python : 20 minutes<br><br>Execution time:<br>C: 20 seconds<br>Python: 11 seconds !!<br><br>Who dares to ask Python is slow ?<br><br>cheers,<br>Stef<br><br><br><br><br><br><br>C: 20 seconds<br>Python <br><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
--<br>
<br>
Jani Tiainen<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>