collections.namedtuple implemented in c.
An implementation of namedtuple written in c for warp speed.
Tested against Python 3.4 and 3.5, and 3.6 as of 3084914245d2
Time to go fast.
Use qualified imports so that we can tell which namedtuple we are using.
>>> from namedtuple import namedtuple as cnamedtuple >>> from collections import namedtuple as stdnamedtuple >>> from pickle import dumps, loads
These operations scale with the number of fields.
Type creation from a string of field names.
Type creation from a sequence of field names.
Less cute numbers
These operations do not scale with number of fields.
std_inst is an instance of a collections.namedtuple created type with six named fields: a, b, c, d, e, and f.
c_inst is an instance of a cnamedtuple.namedtuple created type with six named fields: a, b, c, d, e, and f.
In : %timeit std_inst.c 10000000 loops, best of 3: 71.9 ns per loop In : %timeit c_inst.c 10000000 loops, best of 3: 38.4 ns per loop
In : %timeit loads(dumps(std_inst)) 100000 loops, best of 3: 6.28 µs per loop In : %timeit loads(dumps(c_inst)) 100000 loops, best of 3: 4.72 µs per loop
The project is hosted on github.