STINNER Victor added the comment: Benchmark comparing collections.namedtuple to structseq, to get an attribute:
* Getting an attribute by name (obj.attr): Mean +- std dev: [name_structseq] 24.1 ns +- 0.5 ns -> [name_namedtuple] 45.7 ns +- 1.9 ns: 1.90x slower (+90%) * Getting an attribute by its integer index (obj[0]): (not significant) So structseq is 1.9x faster than namedtuple to get an attribute by name. haypo@speed-python$ ./bin/python3 -m perf timeit -s "from collections import namedtuple; Point=namedtuple('Point', 'x y'); p=Point(1,2)" "p.x" --duplicate=1024 -o name_namedtuple.json Mean +- std dev: 45.7 ns +- 1.9 ns haypo@speed-python$ ./bin/python3 -m perf timeit -s "from collections import namedtuple; Point=namedtuple('Point', 'x y'); p=Point(1,2)" "p[0]" --duplicate=1024 -o int_namedtuple.json Mean +- std dev: 17.6 ns +- 0.0 ns haypo@speed-python$ ./bin/python3 -m perf timeit -s "from sys import flags" "flags.debug" --duplicate=1024 -o name_structseq.json Mean +- std dev: 24.1 ns +- 0.5 ns haypo@speed-python$ ./bin/python3 -m perf timeit -s "from sys import flags" "flags[0]" --duplicate=1024 -o int_structseq.json Mean +- std dev: 17.6 ns +- 0.2 ns --- Getting an attribute by its integer index is as fast as tuple: haypo@speed-python$ ./bin/python3 -m perf timeit --inherit=PYTHONPATH -s "p=(1,2)" "p[0]" --duplicate=1024 -o int_tuple.json ..................... Mean +- std dev: 17.6 ns +- 0.0 ns ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28638> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com