-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71848cb
commit d9d1d23
Showing
9 changed files
with
213 additions
and
13 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative | | ||
|:---|---:|---:|---:|---:| | ||
| `poetry run python benchmarks/chili_decode.py` | 249.4 ± 4.1 | 245.5 | 258.8 | 1.01 ± 0.02 | | ||
| `poetry run python benchmarks/pydantic_decode.py` | 295.5 ± 12.5 | 287.6 | 327.1 | 1.19 ± 0.05 | | ||
| `poetry run python benchmarks/attrs_decode.py` | 260.9 ± 8.6 | 253.2 | 283.5 | 1.05 ± 0.04 | | ||
| `poetry run python benchmarks/chili_encode.py` | 247.8 ± 2.3 | 245.4 | 253.0 | 1.00 | | ||
| `poetry run python benchmarks/pydantic_encode.py` | 292.4 ± 4.7 | 287.1 | 302.5 | 1.18 ± 0.02 | | ||
| `poetry run python benchmarks/attrs_encode.py` | 258.2 ± 2.1 | 254.4 | 261.4 | 1.04 ± 0.01 | | ||
| `poetry run python benchmarks/chili_decode.py` | 246.4 ± 1.6 | 244.8 | 249.6 | 1.00 | | ||
| `poetry run python benchmarks/pydantic_decode.py` | 288.2 ± 1.8 | 284.5 | 291.0 | 1.17 ± 0.01 | | ||
| `poetry run python benchmarks/attrs_decode.py` | 256.6 ± 1.8 | 253.3 | 259.5 | 1.04 ± 0.01 | | ||
| `poetry run python benchmarks/marshmallow_decode.py` | 256.8 ± 5.4 | 252.2 | 271.0 | 1.04 ± 0.02 | | ||
| `poetry run python benchmarks/chili_encode.py` | 248.8 ± 4.2 | 243.6 | 256.5 | 1.01 ± 0.02 | | ||
| `poetry run python benchmarks/pydantic_encode.py` | 298.0 ± 14.4 | 288.3 | 325.7 | 1.21 ± 0.06 | | ||
| `poetry run python benchmarks/attrs_encode.py` | 257.9 ± 3.6 | 252.6 | 263.4 | 1.05 ± 0.02 | | ||
| `poetry run python benchmarks/marshmallow_encode.py` | 254.0 ± 2.7 | 250.9 | 260.6 | 1.03 ± 0.01 | |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,5 +51,5 @@ class Book: | |
), | ||
] | ||
|
||
encoded = unstructure(books) | ||
print(encoded) | ||
raw_data = unstructure(books) | ||
print(raw_data) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from marshmallow import Schema, fields, post_load | ||
|
||
|
||
class AuthorSchema(Schema): | ||
first_name = fields.Str() | ||
last_name = fields.Str() | ||
|
||
@post_load | ||
def make_author(self, data, **kwargs): | ||
return Author(**data) | ||
|
||
|
||
class Author: | ||
def __init__(self, first_name, last_name): | ||
self.first_name = first_name | ||
self.last_name = last_name | ||
|
||
|
||
class TagSchema(Schema): | ||
name = fields.Str() | ||
|
||
@post_load | ||
def make_tag(self, data, **kwargs): | ||
return Tag(**data) | ||
|
||
|
||
class Tag: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
|
||
class Book: | ||
def __init__(self, name, author, tags, isbn=None): | ||
self.name = name | ||
self.author = author | ||
self.tags = tags | ||
self.isbn = isbn | ||
|
||
|
||
class BookSchema(Schema): | ||
name = fields.Str() | ||
author = fields.Nested(AuthorSchema) | ||
tags = fields.Nested(TagSchema, many=True) | ||
isbn = fields.Str() | ||
|
||
@post_load | ||
def make_book(self, data, **kwargs): | ||
return Book(**data) | ||
|
||
|
||
raw_data = [ | ||
{ | ||
"name": "The Hobbit", | ||
"author": {"first_name": "J.R.R.", "last_name": "Tolkien"}, | ||
"tags": [{"name": "Fantasy"}, {"name": "Adventure"}], | ||
}, | ||
{ | ||
"name": "The Lord of the Rings", | ||
"author": {"first_name": "J.R.R.", "last_name": "Tolkien"}, | ||
"tags": [{"name": "Fantasy"}, {"name": "Adventure"}], | ||
}, | ||
{ | ||
"name": "The Silmarillion", | ||
"author": {"first_name": "J.R.R.", "last_name": "Tolkien"}, | ||
"tags": [{"name": "Fantasy"}, {"name": "Adventure"}], | ||
}, | ||
{ | ||
"name": "The Children of Húrin", | ||
"author": {"first_name": "J.R.R.", "last_name": "Tolkien"}, | ||
"tags": [{"name": "Fantasy"}, {"name": "Adventure"}], | ||
}, | ||
{ | ||
"name": "The Fall of Gondolin", | ||
"author": {"first_name": "J.R.R.", "last_name": "Tolkien"}, | ||
"tags": [{"name": "Fantasy"}, {"name": "Adventure"}], | ||
}, | ||
] | ||
|
||
book_schema = BookSchema(many=True) | ||
|
||
books = book_schema.load(raw_data) | ||
print(books) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from marshmallow import Schema, fields, post_load | ||
|
||
|
||
class AuthorSchema(Schema): | ||
first_name = fields.Str() | ||
last_name = fields.Str() | ||
|
||
@post_load | ||
def make_author(self, data, **kwargs): | ||
return Author(**data) | ||
|
||
|
||
class Author: | ||
def __init__(self, first_name, last_name): | ||
self.first_name = first_name | ||
self.last_name = last_name | ||
|
||
|
||
class TagSchema(Schema): | ||
name = fields.Str() | ||
|
||
@post_load | ||
def make_tag(self, data, **kwargs): | ||
return Tag(**data) | ||
|
||
|
||
class Tag: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
|
||
class Book: | ||
def __init__(self, name, author, tags, isbn=None): | ||
self.name = name | ||
self.author = author | ||
self.tags = tags | ||
self.isbn = isbn | ||
|
||
|
||
class BookSchema(Schema): | ||
name = fields.Str() | ||
author = fields.Nested(AuthorSchema) | ||
tags = fields.Nested(TagSchema, many=True) | ||
isbn = fields.Str() | ||
|
||
@post_load | ||
def make_book(self, data, **kwargs): | ||
return Book(**data) | ||
|
||
books = [ | ||
Book( | ||
name="The Hobbit", | ||
author=Author(first_name="J.R.R.", last_name="Tolkien"), | ||
tags=[Tag(name="Fantasy"), Tag(name="Adventure")], | ||
), | ||
Book( | ||
name="The Lord of the Rings", | ||
author=Author(first_name="J.R.R.", last_name="Tolkien"), | ||
tags=[Tag(name="Fantasy"), Tag(name="Adventure")], | ||
), | ||
Book( | ||
name="The Silmarillion", | ||
author=Author(first_name="J.R.R.", last_name="Tolkien"), | ||
tags=[Tag(name="Fantasy"), Tag(name="Adventure")], | ||
isbn="978-0261102736", | ||
), | ||
Book( | ||
name="The Children of Húrin", | ||
author=Author(first_name="J.R.R.", last_name="Tolkien"), | ||
tags=[Tag(name="Fantasy"), Tag(name="Adventure")], | ||
), | ||
Book( | ||
name="The Fall of Gondolin", | ||
author=Author(first_name="J.R.R.", last_name="Tolkien"), | ||
tags=[Tag(name="Fantasy"), Tag(name="Adventure")], | ||
), | ||
] | ||
|
||
book_schema = BookSchema(many=True) | ||
|
||
raw_data = book_schema.dump(books) | ||
print(raw_data) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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