On 3/23/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > Agreed. I think there's also a perceived performance difference, whether > one exists or not. I'd be real surprised if > > for key, val in somedict.iteritems(): > blah(key, val) > > was faster than > > for key, val in somedict.items(): > blah(key, val) > > for small dicts. Still, around work I see a great preference for the longer
Not sure what's a "small dict" in your world -- here, for example: python2.4 -mtimeit -s'd=dict.fromkeys(range(23))' 'for k, v in d.iteritems(): pass' 100000 loops, best of 3: 2.81 usec per loop python2.4 -mtimeit -s'd=dict.fromkeys(range(23))' 'for k, v in d.items(): pass' 100000 loops, best of 3: 4.82 usec per loop and an avoidable overhead of 2.01/2.81 = 71.5% does matter. But maybe you mean dictionaries that are much smaller than a couple dozen items? Using range(3) instead of range(23), I measure 0.804 vs 1.36 microseconds -- still, even that 68% avoidable overhead, while definitely less than 71.5%, is still pretty unpleasant, no? Alex _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
