|
|
|
|
|
by mjschultz
4502 days ago
|
|
I'm probably doing it wrong but I measured exactly this yesterday and the dict version was faster: $ python -m timeit --setup "from collections import namedtuple; Point = namedtuple('Point', ['x', 'y']); p = Point(x=0, y=0)" "p.x + p.y"
1000000 loops, best of 3: 0.284 usec per loop
vs. $ python -m timeit --setup "p = {'x': 0, 'y': 0}" "p['x'] + p['y']"
10000000 loops, best of 3: 0.0737 usec per loop
Maybe the use isn't right because I agree with your belief that namedtuple is suppose to be more performant. |
|