Re:Why Python Runs Slow, Part 1: Data Structures
by pdonis on Thursday February 13, 2014 @09:35AM
(#7231558)
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.
[ Parent
| on HN ]
Re:Why Python Runs Slow, Part 1: Data Structures
by mjschultz on Thursday February 13, 2014 @10:40AM
(#7231876)
That 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.
Re:Why Python Runs Slow, Part 1: Data Structures
by pdonis on Thursday February 13, 2014 @08:53PM
(#7236336)
Ah, 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.