This file contains hidden or 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 sys | |
import importlib.metadata | |
import timeit | |
from dataclasses import dataclass | |
import msgspec | |
import orjson | |
from mashumaro.codecs.json import JSONEncoder, JSONDecoder | |
from mashumaro.codecs.orjson import ORJSONEncoder, ORJSONDecoder |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 is a modified version of `orig_benchmark.py`, using different data to | |
# highlight performance differences. | |
import json | |
import random | |
import string | |
import timeit | |
from statistics import mean, stdev | |
import orjson | |
import simdjson |
This file contains hidden or 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
from datetime import date | |
from enum import StrEnum, auto | |
from typing import Annotated | |
from msgspec import Struct, Meta | |
class OrderStatus(StrEnum): | |
OPEN = auto() | |
CLOSED = auto() |
This file contains hidden or 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
"""A quick benchmark comparing how quickly `__init__` with default values runs | |
for various dataclass-like libraries. | |
We also compare against the time it takes to initialize a `dict` or `tuple` | |
with the same data, as a "low-bar" for pure-python implementations. | |
""" | |
import timeit | |
import attrs |
This file contains hidden or 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
"""An example key-value store server and client implementation using msgspec | |
and asyncio. | |
Requests are serialized using the MessagePack protocol, as implemented by | |
msgspec. Additionally, all messages are length-prefix framed using a 32 bit | |
big-endian integer. | |
Note that this encoding isn't tied to either asyncio or msgspec - this could | |
just as easily be implemented using sockets and a different serialization | |
protocol. Length-prefix framing is useful in that respect - it separates the IO |
This file contains hidden or 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 ibis | |
from ibis import _ | |
con = ibis.datasette.connect("https://scotrail.datasette.io/scotrail") | |
t = con.tables.announcements | |
def random(category): | |
return ( | |
t.filter(_.Category == category) | |
.sort_by(ibis.random()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
In [1]: import ibis | |
In [2]: ibis.options.interactive = True # enable interactive mode | |
In [3]: con = ibis.sqlite.connect("legislators.db") # connect to a database | |
In [4]: legislators = con.tables["legislators"] # access tables | |
In [5]: legislators.groupby("bio_gender").count() # query using a dataframe-like API | |
Out[5]: |
NewerOlder