4 ms·
You should be creating a dict vs. a namedtuple instance once, then accessing it many, many times. What you're doing is creating a lot of dict vs. namedtuple ins
by pdonis 13y ago
You should be creating a dict vs. a namedtuple instance once, then accessing it many, many times. What you're doing is creating a lot of dict vs. namedtuple instances, then accessing each one only once. That's mostly testing the instance creation time, not the field access time.
- mjschultz 13y agoThat code should only create the dict/namedtuple instance once, then access it many, many times. The creation occurs in the --setup portion. The field accesses occur in the actual looping portion of the timeit code.
- pdonis 13y agoAh, ok, I see, for some reason my browser wasn't showing the namedtuple code snippet right. Now I need to go look at the namedtuple code to see why accessing the fields by name is slower than accessing them by index.