Created
September 10, 2021 20:19
-
-
Save iaindillingham/76943437ce41676621665e8b92d66a95 to your computer and use it in GitHub Desktop.
Data Classes vs Named Tuples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dataclasses | |
import random | |
import typing | |
@dataclasses.dataclass | |
class PointDC: | |
x: float | |
y: float | |
@profile | |
def make_points_dc(): | |
return [PointDC(random.random(), random.random()) for x in range(1_000_000)] | |
class PointNT(typing.NamedTuple): | |
x: float | |
y: float | |
@profile | |
def make_points_nt(): | |
return [PointNT(random.random(), random.random()) for x in range(1_000_000)] | |
if __name__ == "__main__": | |
make_points_dc() | |
make_points_nt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment