Populating a dictionary, fast
Alberto Berti
alberto at metapensiero.it
Sun Nov 11 12:58:55 EST 2007
>>>>> "Michael" == Michael Bacarella <mbac at gpshopper.com> writes:
>> > This would seem to implicate the line id2name[id] = name as
>> being
Michael> excruciatingly slow.
>>
>> As others have pointed out there is no way that this takes 45
>> minutes.Must be something with your system or setup.
>>
>> A functionally equivalent code for me runs in about 49 seconds!
>> (it ends up using about twice as much ram as the data on disk)
Michael> You can download the list of keys from here, it's 43M
Michael> gzipped: http://www.sendspace.com/file/9530i7
Michael> and see it take about 45 minutes with this:
I've downloaded your keys, run your program and this is the result:
$ du -h keys.txt
128M keys.txt
$ time python cache_keys.py
real 0m55.913s
user 0m35.286s
sys 0m0.852s
$ python
Python 2.4.4 (#2, Apr 26 2007, 00:02:45)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
$ uname -a
Linux lizard 2.6.21-1-k7 #1 SMP Sat May 26 16:56:05 UTC 2007 i686 GNU/Linux
cheers
Alberto
More information about the Python-list
mailing list