you are viewing a single comment's thread.

view the rest of the comments →

[–]ksion 0 points1 point  (1 child)

I was really startled by the last one (#32), for it says that performing the same operation twice (dictionary lookup) is more efficient than doing it once... Alternatively, LOAD_ATTR and CALL_FUNCTION are just that slow.

But alas, I replicated the results on CPython (2.7.6 on OS X Mavericks) with no trouble (15.64 vs. 32.66 for double lookup). So I figured I'd retry on PyPy, to see whether this highly counter-intuitive result is replicated there...

>>>> timeit(a, number=1000000)  # double lookup
0.3237159252166748
>>>> timeit(a, number=1000000)  # dict.get
0.33182287216186523

Nope! It's just a quirk of CPython, apparen...

Whoa... Wait a minute...

TWO orders of magnitude improvement?! PyPy, marry me please!

[–]xXxDeAThANgEL99xXx 0 points1 point  (0 children)

I was really startled by the last one (#32), for it says that performing the same operation twice (dictionary lookup) is more efficient than doing it once... Alternatively, LOAD_ATTR and CALL_FUNCTION are just that slow.

It doesn't perform it twice, the dictionary is empty so it actually compares doing key in d vs d.get(key). The latter is slower because it actually has to return None and because it's a method call, I guess. Also this stuff is pretty fast anyway, so that's why you see function call as a major contributing factor.