[Yum-devel] [PATCH] make sure when we return items we sort the counts of things matched from the tagsdb into the rest of the matches. FIXME added to get rid of the silly sorting list as it appears to only want to make me cry

Seth Vidal skvidal at fedoraproject.org
Fri Mar 12 21:46:08 UTC 2010



On Fri, 12 Mar 2010, Ville Skyttä wrote:

> On Friday 12 March 2010, Seth Vidal wrote:
>
>> http://fpaste.org/aOLJ/raw/
>>
>> this script measures 3 mechanism for making a dict like we're describing.
>>
>> run it yourself - but dict3 is using:
>>
>> if not item in dict:
>>      dict[item] = []
>>
>>
>> dict1 is one setdefault
>> dict2 is a pretty bizarre setdefault
>>
>> long story short - dict3 is twice as fast as dict1 and a bazillion times
>> faster than dict2.
>
> BTW with Python >= 2.5 collections.defaultdict(list) would be one more
> alternative, even faster and in my opinion also the most readable.
>
> import collections
> def dict_4():
>    d = collections.defaultdict(list)
>    for y in xrange(0, 100000):
>        word2 = WORDS[y%3]
>        d[word2].append(y)


I tested this one. the speed difference seems to be about 7%


> But I suppose yum is supposed to run with Python 2.4 still so this is not an
> option, at least yet.  And they behave differently from normal dicts so they
> need to be used carefully and can't be just blindly used as a replacement,
> especially as API values.

yah -we need to still run on rhel5.

-sv


More information about the Yum-devel mailing list