I'd venture that it's a simple oversight. items() is likely taking
more memory in addition to being slower because it creates a list of
the items while iteritems simply returns an iterator.
On Mar 24, 9:51 am, David Cramer <[EMAIL PROTECTED]> wrote:
> Ive been having to dig into code vs documentation lately, and there
> are *tons* of uses of items() vs iteritems(). I was wondering why this
> is?
>
> I did a quick benchmark, on an example I found in newforms, to try and
> give myself an answer:
>
> In [31]: timeit.Timer("attrs2=attrs.copy();[(field_name,
> attrs2.pop(field_name)) for field_name, obj in attrs2.items()]",
> "attrs = dict((('adfadsfasdf', 'hello'),)*10)").timeit()
> Out[31]: 1.7580790519714355
>
> In [32]: timeit.Timer("attrs2=attrs.copy();[(field_name, obj) for
> field_name, obj in attrs2.iteritems()]", "attrs =
> dict((('adfadsfasdf', 'hello'),)*10)").timeit()
> Out[32]: 1.2866780757904053
>
> The first example is what's currently in new forms, and I can't see it
> saving much memory, for being that much slower.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---