by jammycrisp · 5y ago · 0 comments
Mirroring the author's initialization benchmark:
In [1]: import msgspec
In [2]: from typing import NamedTuple
In [3]: class Point(msgspec.Struct):
...: x: int
...: y: int
...:
In [4]: class PointNT(NamedTuple):
...: x: int
...: y: int
...:
In [5]: %timeit Point(1, 2)
48.4 ns ± 0.195 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [6]: %timeit PointNT(1, 2)
185 ns ± 0.851 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)