Populating a dictionary, fast
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sun Nov 11 13:04:02 EST 2007
On Sun, 11 Nov 2007 08:51:37 -0800, Michael Bacarella wrote:
>> 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)
>
> You can download the list of keys from here, it's 43M gzipped:
> http://www.sendspace.com/file/9530i7
>
> and see it take about 45 minutes with this:
>
> $ cat cache-keys.py
> #!/usr/bin/python
> v = {}
> for line in open('keys.txt'):
> v[long(line.strip())] = True
Takes about 40 seconds here.
bj at s8n:~$ time python test.py
real 0m38.758s
user 0m25.290s
sys 0m1.580s
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list